473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Environment Variables in WSH JS


In javascript executed by Windows Scripting Host, one can input via
command-line parameters : File $95.js :-
x = WScript.Arguments
WScript.echo("Result:", x.length, typeof x, x[1], "OK")

Prompt>cscript //nologo $95.js 66 77 88
Result: 3 object 77 OK
The Arguments are 0-based.

Can one read/write Environment variables, and if so how? An answer for
VBscript could be useful, as well or in lieu.
Aside : <FAQENTRY> 2.11 : "over 5 years" is IMHO ambiguous. Suggest
"more than 5 years" or "for 5 years", whichever is meant.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
Jul 20 '05 #1
3 9393
Dr John Stockton wrote:
Can one read/write Environment variables, and if so how? An answer for
VBscript could be useful, as well or in lieu.


Use the WshShell object to read the Environment property:

---
var ws, en, buf;

ws=WScript.CreateObject("WScript.Shell");
en=new Enumerator(ws.Environment)
buf=[];

for(;!en.atEnd();en.moveNext())
buf.push(en.item());

WScript.Echo(buf.join("\n"));
ws=null;
---

Reference:<URL:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsProEnvironment.asp>
Download:<URL:http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp>
HTH
Yep.
Jul 20 '05 #2
JRS: In article <3f***********************@news.free.fr>, seen in
news:comp.lang.javascript, Yann-Erwan Perio <y-*******@em-lyon.com>
posted at Tue, 6 Jan 2004 22:28:34 :-
Dr John Stockton wrote:
Can one read/write Environment variables, and if so how? An answer for
VBscript could be useful, as well or in lieu.


Use the WshShell object to read the Environment property:

---
var ws, en, buf;

ws=WScript.CreateObject("WScript.Shell");
en=new Enumerator(ws.Environment)
buf=[];

for(;!en.atEnd();en.moveNext())
buf.push(en.item());

WScript.Echo(buf.join("\n"));


Thanks; that works for me (except for buf.push), and I can also now read
in VBscript. But can Environment variables be written from these
languages? To do it in Pascal, I had to work low-level.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
Jul 20 '05 #3
Dr John Stockton wrote:
But can Environment variables be written from these
languages? To do it in Pascal, I had to work low-level.


Far from being a WSH specialist I'm afraid I cannot give you as a
definite answer about this as I'd like to. Still, some quick lookup in
the archives yielded the two following articles, which might be of
interest for you:

<URL:http://groups.google.com/groups?hl=fr&lr=&ie=UTF-8&oe=UTF-8&selm=e52812c2BHA.2588%40tkmsftngp07>
<URL:http://groups.google.com/groups?hl=fr&lr=&ie=UTF-8&oe=UTF-8&selm=3F54F46F.59CADE82%40hydro.com>

The quick story is that you can set environment variables via WSH,
though the way you do it depends on which platforms you set the
variable, and whether you want to set it permanently.

var System=Script.CreateObject("WScript.Shell").Enviro nment("SYSTEM");
System("foo")="bar";
WScript.Echo(System("foo"));

....should work on win2k/XP and make the variable available to other
processes/users. Using "USER" instead of "SYSTEM" makes it available to
the current user only, and using "PROCESS" makes it available to the
current process only.

Windows 95/98 only support "PROCESS", so you cannot make the variable
permanent unless using the "winset" utility.
HTH
Yep.
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Artco News | last post by:
How to get Windows XP Server(where PHP Server is running) environment variables? I use the echo $_ENV seem to not working. The same for any other environment variables. I'm running PHP-4.3.4...
3
by: Jim Potts | last post by:
What is the best way in Python version 2.x to read/get Windows (nt/2000/xp) system and user environment variables? Thanks for the help! jep
3
by: Greg Lindstrom | last post by:
Hello- I am running python 2.3. on an HP-9000 box running Unix and have a POSIX script that sets up my production environment. I would like to run the script from inside a python routine and...
4
by: Ron Clarke | last post by:
I have an application that starts other processes. The app needs to create/set a few environment variables when a process starts, let the process run, then remove the environment variables when the...
1
by: darrel | last post by:
We've purchased a component that requires us to install two DLLs. One we add as a reference to our project, but the otherone we have to add to the 'environment setup' as a system path reference....
1
by: pagates | last post by:
Hi All, What's the "best" way to get System Environment Variables (VS2003)? Environment.GetEnvironmentVariable("xxx") only gets user Environment variables. Thanks, pagates
2
by: ANarula | last post by:
I am running into a strange problem. I have perl script which reads the "APPDATA" environment variable, and does some work on that directory. When I a launch this script from Command Prompt, it...
0
by: Tristan | last post by:
Hello community: I post this because I could not find satisfactory answers in the posts generated by this nice group. I work on winXP. I have many little python applications in different folders,...
3
by: Tristan | last post by:
Hello community: I post this because I could not find satisfactory answers in the posts generated by this nice group. I work on winXP. I have many little python applications in different folders,...
3
by: smitty1e | last post by:
Just a fun exercise to unify some of the major input methods for a script into a single dictionary. Here is the output, given a gr.conf file in the same directory with the contents stated below: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.