
Setting environment Variables via VB Script
You know, you're right. The WSH help is not well written in this
regard, but I did finally find an example that illustates the
approach. It was presented for the Remove methode as such ...
Example
The following code removes the Process environment variable TestVar.
'[VBScript]
Dim WshShell, WshEnv
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("PROCESS")
WshEnv("TestVar") = "Windows Script Host" ' <-- this sets the
variable
WScript.Echo WshShell.ExpandEnvironmentStrings(_
"The value of the test variable is: '%TestVar%'")
WshEnv.Remove "TestVar"
WScript.Echo WshShell.ExpandEnvironmentStrings(_
"The value of the test variable is: '%TestVar%'")
(I modified the example slightly to deal with the Email client word
wrapping issue.)
Note that only "Process" variables are supported in Win 98/ME. Win
NT/2000/XP also have "User" and "Volatile" environments. Also, note
that varibles cannot be passed to the currently running console
(MS-DOS session) using this approach. AFAIK, this can only be done by
echoing out a "SET TESTVAR=..." string to a secondary batch/cmd file
or 'FOR /F ...' statement. See the earlier thread on Google ...
http://
groups.google.com/groups?threadm=Rfmdna3nYugzgd6jXTWcow%40fcc.net&rnum=13
That should all be one URL line, but is wrapped by my Email client.
Tom Lavedas
===========
Quote:
> I'm searching for a way to set system environment variables via vb script.
> Reading Environment Strings is not the problem (expandenvironmentstrings)
> but setting.
> Can anybody help me ?
> Thanks for every idea
> Alex Fischer