Environment Variables in WSH JS

Discussion in 'Javascript' started by Dr John Stockton, Jan 6, 2004.

  1. 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.
    Dr John Stockton, Jan 6, 2004
    #1
    1. Advertising

  2. 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.
    Yann-Erwan Perio, Jan 6, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benjamin Bittner

    IISFAQ WSH Script in/to DotNet

    Benjamin Bittner, Jun 28, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    858
    M. Zeeshan Mustafa
    Jun 28, 2004
  2. David Josty

    wsh and Python

    David Josty, Apr 9, 2005, in forum: Python
    Replies:
    1
    Views:
    450
    Roger Upole
    Apr 10, 2005
  3. misiek3d
    Replies:
    1
    Views:
    369
    Dino Viehland
    Jun 28, 2007
  4. GaryLee
    Replies:
    2
    Views:
    504
    GaryLee
    Sep 17, 2007
  5. kyiu

    lost in ASP & WSH!please help!

    kyiu, Jul 11, 2003, in forum: ASP General
    Replies:
    1
    Views:
    140
    Dhananjay Modak
    Jul 11, 2003
Loading...

Share This Page