Return a Windows Environment variable.


   objShell   A WScript.Shell object 

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


'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 VBScript commands

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

Copyright © 1999-2024 SS64.com
Some rights reserved