Page 1 of 1

Windows environment variable

Posted: 20 Aug 2018 12:04
by alexandredneto
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.

Re: Windows environment variable

Posted: 20 Aug 2018 12:51
by aGerman
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