Can I pick up environment variables in vbscript WSH script?

mike nelson picture mike nelson · May 24, 2009 · Viewed 66.5k times · Source

Is is possible to read system environment variables in a Windows Scripting Host (WSH) VBS script?

(I am writing a VBScript using Windows Scripting Host for task for a Cruise Control and want to pick up the project build URL.)

Answer

M4N picture M4N · May 24, 2009

Here's an example (taken from here):

Set oShell = CreateObject( "WScript.Shell" )
user=oShell.ExpandEnvironmentStrings("%UserName%")
comp=oShell.ExpandEnvironmentStrings("%ComputerName%")
WScript.Echo user & " " & comp