WshShell.Environment

Return a Windows Environment variable.

Syntax 
      WshShell.Environment([strType]) 

Key:
    strType is one of
      "System" (HKLM),
      "User"   (HKCU),
      "Volatile" or "Process"

Example

'Write to env variables
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Environment("USER").Item("MyVar1") = "hello"
WshShell.Environment("USER").Item("MyVar2") = "world"

'Read Env Variables
WScript.Echo WshShell.Environment("USER").Item("MyVar1")
WScript.Echo WshShell.Environment("USER").Item("MyVar2") 

' Retrieve the %COMPUTERNAME% system environment variable
WScript.Echo WshShell.Environment("PROCESS").Item("COMPUTERNAME") 

".Item" is actually the default property and can be omitted

"It is possible to store the mind with a million facts and still be entirely uneducated" - Alec Bourne

Related:

Environment variables - Expand - .Delete/Remove
Equivalent Windows CMD command: SET - Display, set, or remove environment variables
Equivalent Powershell command: Get-Item env:HOMEDRIVE or $env:HOMEDRIVE



Back to the Top

© Copyright SS64.com 1999-2011
Some rights reserved