Discussion:
is there a way to set user enviroment from vbscript?
(too old to reply)
jg
2005-11-30 20:46:45 UTC
Permalink
I tried the example from the script help

Dim WshShell, WshEnv
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("USER") ' I replaced PROCESS with USER
hoping for better result
WshEnv("TestVar") = "Windows Script Host"

However when the script finishes, there is no TestVar around in the dos
prompt that executed the script..

I only need the set an environment variable just for the DOS prompt session.
Michael Harris (MVP)
2005-12-01 04:38:18 UTC
Permalink
Post by jg
I tried the example from the script help
Dim WshShell, WshEnv
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("USER") ' I replaced PROCESS
with USER hoping for better result
WshEnv("TestVar") = "Windows Script Host"
However when the script finishes, there is no TestVar around in the
dos prompt that executed the script..
I only need the set an environment variable just for the DOS prompt session.
For a command shell (cmd.exe) hosted script (a bat or cmd) that executes a
WSH hosted script, the environment is a one way resource for passing
environment variables. The script runs within another child process
(wscript/cscript). That child process gets a copy of the environment from
the parent process (cmd.exe) but any change made to that copy is not
propagated back to the original environment of the parent cmd.exe process.

The WSH hosted script can (assuming it is cscript hosted) use wscript.echo
to write information back via the standard output stream. That stream
output can be piped or redirected in the parent command shell, but I don't
know of any way for that to be captured in a variable accessible by the
parent command shell itself.
--
Michael Harris
Microsoft MVP Scripting
Loading...