.Environment

Return a Windows Environment variable.

Syntax 
      objShell.Environment([strType]) 

Key:
   objShell   A WScript.Shell object 

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

Example

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

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

' Retrieve the %COMPUTERNAME% system environment variable
WScript.Echo objShell.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


© Copyright SS64.com 1999-2014
Some rights reserved