Torgeir
Thu Dec 04 06:35:22 CST 2003
zurg wrote:
> TheWshShell.ExpandEnvironmentStrings function returns the systems constants
> like "C:\Windows" for
> "%SYSTEMROOT%".
> But how to set one of this constants?
> I tried WshShell.Run "set DAN = c:\"
> but I get "Couldn't find the file" (I translated it from my language so it
> may sound a little diffrent)
Hi
Create/set/change environment variables permanent (WNT/W2k/WXP) from VBScript:
'Example for setting a environment variable with name "ASSET" and value "1234"
Set WshShell = CreateObject("WScript.Shell")
' makes environment settings permanent and for all users
' Use "USER" instead of "SYSTEM" to set it for current
' user only, or "PROCESS" to set it for current process only
Set WshSystemEnv = WshShell.Environment("SYSTEM")
' Set your environment variable
WshSystemEnv("ASSET") = "1234"
For Win9x/WinME, only "PROCESS" is available.
For SYSTEM and USER, you usually need a logoff/logon to make the changes take
affect.
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide:
http://www.microsoft.com/technet/scriptcenter