views:

3175

answers:

2

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.)

+4  A: 

From here ...

Set WshShell = WScript.CreateObject("WScript.Shell")

Set WshProccessEnv = WshShell.Environment("Process")
Set WshSysEnv = WshShell.Environment("System")

Wscript.Echo WshSysEnv("NUMBER_OF_PROCESSORS")
Wscript.Echo WsProcessEnv("Path")

Also, much more detail on TechNet.

JP Alioto
+3  A: 

Here's an example (taken from here):

Set oShell = CreateObject( "WScript.Shell" )
user=oShell.ExpandEnvironmentStrings("%UserName%")
comp=oShell.ExpandEnvironmentStrings("%ComputerName%")
WScript.Echo user & " " & comp
M4N
thanks very much!
mike nelson