my sample script set definitivly the variable , this is not the problem
but for next shells, next sessions, ... ... not in the same CMD or script
Main Topics
Browse All Topicshi,
when i set a User envir variable in vbscript which can be used in the same CMD
all is ok if i run another script (or in another cmd)
but how can use this env variable in my loginscript ?
set-env.vbs
Set objShell = WScript.CreateObject("WScr
Set colSystemEnvVars = objShell.Environment("User
Set val = qeuryID("XXXXXXXXX")
if val <> "" then
colSystemEnvVars("MYVAR") = "val"
.............
login.bat
cscript set-env.vbs
echo %MYVAR%
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>>but for next shells, next sessions, ... ... not in the same CMD or script
As I wrote: "The problem is that an environment variable that is set like that will only be valid during the liftime of your .vbs script."
After your script has exited, the value you have set is gone. If you want it to persist for "next shells, next sessions", you will need to set it in the registry.
There are quiet a few command-line utilities that allow you a save an enviromental variable beyond the scope of the current shell.
I've used the SETX command from the WinXP Support Tools
http://www.microsoft.com/d
I have also been looking for an easy solution to this problem and the current accepted solutions are wrong. What the author asks for is clear. Here is how I suggest doing this.
set-env.vbs
wscript.echo "set MYVAR=Value1"
wscript.echo "set MYVAR2=Value2"
.............
login.bat
call cscript //Nologo set-env.vbs > %tempt%\setVars.bat
call %TEMP%\setVars.bat
echo %MYVAR%
This will output to the console:
Value1
Explanation:
Since the current scope of the cmd.exe running cannot be altered by either WMI, setx or the registry, the only way is to set the variable in the current environment.
call cscript //Nologo set-env.vbs > %tempt%\setVars.bat
This will redirect all output of set-env.vbs to a file named setVars.bat. Make sure all wscript.echo commands output valid batch code. Using "call" is important in order to wait for the called script to finish before continuing the logon script.
call %TEMP%\setVars.bat
This executes in the current scope the batch file created from the output of set-env.vbs.
The variables are then available for use.
I hope this could help anyone in this situation.
Business Accounts
Answer for Membership
by: jkrPosted on 2006-05-11 at 08:51:16ID: 16659707
The problem is that an environment variable that is set like that will only be valid during the liftime of your .vbs script. If you want it to persist, you'll need to set ist in the registry under HKEY_CURRENT_USER\Environm ent