Thursday, August 12, 2010

VBScript: Working with Windows Environmental Variables

Option explicit

'Declare Variables
Dim WshShl, Shell, UserVar

'Set objects
Set WshShl = WScript.CreateObject("WScript.Shell")
Set Shell = WshShl.Environment("User")

'Read variable
UserVar = Shell("jonas123")

'Output value to msgbox
WScript.Echo "Your name is " & UserVar & "!"

Shell("jonas123") = "monkey"

'Cleanup Objects
Set WshShl = Nothing
Set Shell = Nothing

'Exit Script
WScript.Quit()

No comments: