• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

VBScript to find a specific environment variable

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.
0
wiggs1006
Asked:
wiggs1006
  • 2
  • 2
1 Solution
 
Chris DentPowerShell DeveloperCommented:

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_RETURN_IMMEDIATELY = &H10
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", _
            WBEM_RETURN_IMMEDIATELY + WBEM_FORWARD_ONLY)

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

If booIsPresent = True Then
      MsgBox "Yes"
Else
      MsgBox "No"
End If
0
 
EDDYKTCommented:
just use inputbox and msgbox?

dim response

response = inputbox("enter computer name", "computer name")
response = msgbox("are you sure " & response)
wscript.echo response
0
 
EDDYKTCommented:
forget it, i misread your question
0
 
wiggs1006Author Commented:
Thanks for the help, I was almost there!

Nice work!
0
 
Chris DentPowerShell DeveloperCommented:

Pleasure :)

Chris
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now