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)
Please help,
zurg

Re: Problem with system constants by Torgeir

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



Re: Problem with system constants by zurg

zurg
Thu Dec 04 06:57:22 CST 2003

Thanks for the complete answer - it's god to get all informations about the
subject!
But... doesn't work???
I run this code and tried "set" and "%ASSET%" from the command line and it
didn't return "1234"...
Why?

Code like this:

Set WshShell = CreateObject("WScript.Shell")
Set WshSystemEnv = WshShell.Environment("SYSTEM")
WshSystemEnv("ASSET") = "1234"



Re: Problem with system constants by Torgeir

Torgeir
Thu Dec 04 07:14:21 CST 2003

zurg wrote:

> Thanks for the complete answer - it's god to get all informations about the
> subject!
> But... doesn't work???
> I run this code and tried "set" and "%ASSET%" from the command line and it
> didn't return "1234"...
> Why?
>
> Code like this:
>
> Set WshShell = CreateObject("WScript.Shell")
> Set WshSystemEnv = WshShell.Environment("SYSTEM")
> WshSystemEnv("ASSET") = "1234"

Hi

After running this script, if I open a new command prompt and type SET, I see
the new env. variable. If you want to see it from the script that made the env.
variable, you should set it in the PROCESS environment as well as in the
SYSTEM.



--
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



Re: Problem with system constants by zurg

zurg
Thu Dec 04 07:27:25 CST 2003

Sorry, your're right... I just wrote in command line sth like this:
1. "cscript 1.vbs"
2. "set"
So it didn't returned newly registed value
Too fast - my failure...
Thank you once again,
zurg