Reading environment variables with Javascript

前端 未结 6 857
灰色年华
灰色年华 2020-12-10 10:37

I need to read the system time from the environment variables on the client\'s OS. I searched on Stackoverflow and found that this isn\'t possible. However, those answers we

6条回答
  •  旧巷少年郎
    2020-12-10 11:10

    FWIW.... Just playing around with an .HTA file (yes that uses the MSIE 'engine' so you can probably forget about other browsers) and the following JavaScript reads the %TEMP% path variable to set a filepath+name for safely writing a temporary file. This works OK for me :

    var oTest = new ActiveXObject("wscript.shell");
    pathTest = oTest.ExpandEnvironmentStrings("%TEMP%") + "\\test_it.txt";
    oTest = null;
    alert(pathTest);  // proves we can read %TEMP%
    
    // and create the file, to complete the example
    var oFSO = new ActiveXObject("Scripting.FileSystemObject");
    var fil = oFSO.CreateTextFile(pathTest, true);
    fil.WriteLine("Hello wonderful world!");
    fil.Close();
    

提交回复
热议问题