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 were from 2010 and I want to ask if anything has changed since.
Is it possible with some kind of framework? or Javascript is still sandboxed and cut off from OS?
To retrieve environment variables in Node. JS you can use process. env. VARIABLE_NAME, but don't forget that assigning a property on process.
Environment variables store variables, as the name implies. The values or things that get assigned to these variables could be API keys that you need to perform certain requests or operations. To create an environment variable, all you need to do is create a new file called .
szpic
, if Javascript were not sandboxed from the OS, any half-witted criminal could get onto your computer and take control. Allowing environmental variables is way too low level to ever be allowed.
Take a look at all of your environmental variables and ask yourself if everyone on the planet should have access to all that data about your computer.
If you want to do this with Javascript, you'll have to use a special web browser, such as node-webkit. It isn't going to run on any normal web browser, though, so don't expect more than 0.0001% of the population to expect to run your page.
I don't know your intended use, but one trick, to throw in an environmental variable, is to make a shortcut to your web application, and include it in there as a URL parameter (at least on Winblows).
http://myapp.com?computername=%COMPUTERNAME%
the javascript Date() Object provides the clients system time.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With