VBScript to find a specific environment variable

Posted on 2006-04-19
Last Modified: 2010-04-07
I am looking for a script that will find a specific variable on a Windows XP machine.  I would like the script to prompt for a computer name in the domain and return a yes/no type of answer to whether or not the variable is present.  Do any of you experts know if this is possible?

For example, I would like to start the script, have a input box come up and say: enter a machine name.  Once I do this all I want it a yes/no response.  Does anyone out there have any suggestions on this one?

This would be a specific system variable that I pushed to all of my machines in the domain with SMS 2003.  I just need to confirm this is the user calls in with an issue and a script would be the best for me to save time.

Please send whatever you can.

Thanks in advance.
Question by:wiggs1006
    LVL 70

    Accepted Solution


    The Environmental Variables are accessible as part of the Win32_Environment node in WMI. You'll have to fill in the Variable Name of course...

    Const VARIABLE_NAME = "<Variable Name>"

    Const WBEM_FORWARD_ONLY = &H20

    strComputer = InputBox("Enter Computer Name")

    booIsPresent = False
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Environment", "WQL", _

    For Each objItem in colItems
          If objItem.SystemVariable = True Then
                If objItem.Name = VARIABLE_NAME Then
                      booIsPresent = True
                End If
          End If

    If booIsPresent = True Then
          MsgBox "Yes"
          MsgBox "No"
    End If
    LVL 26

    Expert Comment

    just use inputbox and msgbox?

    dim response

    response = inputbox("enter computer name", "computer name")
    response = msgbox("are you sure " & response)
    wscript.echo response
    LVL 26

    Expert Comment

    forget it, i misread your question
    LVL 2

    Author Comment

    Thanks for the help, I was almost there!

    Nice work!
    LVL 70

    Expert Comment

    by:Chris Dent

    Pleasure :)


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now