Deal with environment variable or registry keyTag(s): WSH VBScript


The WSH provides a an object, WShell, to manipulate the environment.

[env.vbs]

 

Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")

WScript.Echo "The current PATH is " & _
    WSHShell.Environment.item("path")
    
WScript.Echo "Creating a new environment variable called RealHome"
' this variable will exist only during execution 
' time of this script (Win95)   
WSHShell.Environment.item("RealHome") = "Hello world"
WScript.Echo "Realhome is " & _
    WSHShell.Environment.item("RealHome")
    
Set WSHShell = Nothing    
WScript.Quit(0)
[reg.vbs]

Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")

' write in the HKey_Current_User
WSHShell.RegWrite "HKCU\RealHome\", "Welcome"

WSHShell.RegWrite "HKCU\RealHome\How-to", "Java"
WSHShell.RegWrite "HKCU\RealHome\How-to", "Javascript"
WSHShell.RegWrite "HKCU\RealHome\How-to", "PB"
WSHShell.RegWrite "HKCU\RealHome\How-to", "VBScript"

WSCript.Echo "Value of HKCU\Realhome is " & _
    WSHShell.RegRead("HKCU\RealHome\")

Set WSHShell = Nothing
WScript.Quit(0)

blog comments powered by Disqus