Re: How to set environment variable via JScript?
- From: "Walter Zackery" <please_respond_to@xxxxxxxxx>
- Date: Mon, 25 Sep 2006 03:56:27 -0400
Use StdOut to send values back to the batch file and change environmental
variables. For example:
::caller.bat
@echo off
SET MYVAR=Original value of MYVAR
echo Value of MYVAR is: %MYVAR%
echo Running script ...
for /f "tokens=*" %%a in ('cscript setvar.js') do %%a
echo Value of MYVAR is: %MYVAR%
pause
//setvar.js
WScript.StdOut.WriteLine("Set MYVAR=New value of MYVAR")
"David Mayerovitch" <davmay@xxxxxxxxxxxx> wrote in message
news:OkxEbFt3GHA.1288@xxxxxxxxxxxxxxxxxxxxxxx
I am running Windows XP Home with SP2.
From a batch file ("caller.bat") I would like call a JScript file
("setvar.js") to set the value of a DOS environment variable (MYVAR) which
the batch file could then manipulate. (I need to do some tweaking of
strings that the DOS batch language is incapable of doing.)
But I find with the following test files that the script fails to change
MYVAR from its original value. This failure occurs whether I use "USER",
"SYSTEM", "VOLATILE" or "PROCESS" as the parameter to the Environment
property of the WScript.Shell object.
Can anyone tell me why this setup is not working and how I can fix it?
Thanks.
David
-------------------------------------
Text of batch file "caller.bat":
-------------------------------------
@echo off
SET MYVAR=Original value of MYVAR
echo Value of MYVAR is: %MYVAR%
echo Running script ...
cscript setvar.js
echo Value of MYVAR is: %MYVAR%
pause
-------------------------------------
Text of script file "setvar.js":
-------------------------------------
function setEnvVariable(mystring){
WScript.Echo("This is setvar.js");
var sh=WScript.CreateObject("WScript.Shell");
var userEnv=sh.Environment("USER");
userEnv("MYVAR")=mystring;
return;
}
setEnvVariable("New value of MYVAR");
-------------------------------------
.
- Follow-Ups:
- Re: How to set environment variable via JScript?
- From: David Mayerovitch
- Re: How to set environment variable via JScript?
- References:
- How to set environment variable via JScript?
- From: David Mayerovitch
- How to set environment variable via JScript?
- Prev by Date: Re: Drag Drop between Windows
- Next by Date: Disable javascript clipboard getdata
- Previous by thread: Re: How to set environment variable via JScript?
- Next by thread: Re: How to set environment variable via JScript?
- Index(es):
Relevant Pages
|