How to pass an Environment Variable to change a registry value?
- By Ramesh Srinivasan
- Published March 26, 2006
How to pass an Environment Variable to a Registry change? I have a REG with the following contents.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\MySoft\Options]
"ComputerName"="%computername%"
[HKEY_CURRENT_USER\Software\MySoft\Options]
"ComputerName"="%co
All I want to do is when I run the REG file, the %computername% variable be substituted to the *actual* value (name of the computer).
This cannot be accomplished using a REG file, but this VBScript will do the trick. Copy the lines to Notepad, and save it with a .VBS extension. Run the file.
Set WshShell = CreateObject("Wscript.Shell")
sValue = WshShell.ExpandEnvironmentStrings _
("%computername%")
sKey = "HKCU\Software\MySoft\Options\"
WshShell.RegWrite sKey & "ComputerName", sValue, "REG_SZ"
Set WshShell = Nothing
sValue = WshShell.ExpandEnvironmentStrings _
("%comp
sKey = "HKCU\Software\MySoft\
WshShell.RegWrite sKey & "ComputerName", sValue, "REG_SZ"
Set WshShell = Nothing
