Windows environment variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alexandredneto
Posts: 39
Joined: 28 Feb 2013 13:40

Windows environment variable

#1 Post by alexandredneto » 20 Aug 2018 12:04

Hello!

How to display in JavaScript code any Windows environment variable?

How to display in JavaScript code any Windows environment variable?

I think it is possible using Internet Explorer ActiveX and the oShell.Run () command. Can not have .bat on the client side.

Thank you.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Windows environment variable

#2 Post by aGerman » 20 Aug 2018 12:51

You know that this is a Windows Batch forum?
Nevermind.
*.js

Code: Select all

var objWSHShell = new ActiveXObject('WScript.Shell'),
    objProcEnv = objWSHShell.Environment('PROCESS');

for(var enumProcVars = new Enumerator(objProcEnv); !enumProcVars.atEnd(); enumProcVars.moveNext())
{
  var arrPair = enumProcVars.item().split('='),
      strName = arrPair[0],
      strValue = objWSHShell.ExpandEnvironmentStrings(arrPair[1]);
  WScript.Echo(strName + '=' + strValue);
}
This will work as stand alone script. I don't expect that anything like that will work in a browser since every browser does some kind of sandboxing and strictly restricts the access of websites to the client machine (fortunately!).

Steffen

Post Reply