10

I know that from JavaScript it is not possible to get or set Windows Environment Variables. I have deployed a Electron app as a executable (as suggested here), is it possible now to get or modify a Windows Enviroment Variable. If it is can someone point me in the right direction ?

1

1 Answer 1

15

You can use NodeJs to read the enviroment variables via process.env you can read all methods and possabilities on the process documentation.

Example:

console.log(process.env.PATH)

Writing environment variables in a running process is always temporary. You can set environment variables by calling/spawning system commands/tools like setx under windows.

Persisting them does not change the running environment in the process for that you have to restart the process. So you need both, set the variable as described above and in addition persist it with system tools/commands.

2
  • where do you see the ability to write environment variables? All I see in the docs you link is that any changes to variables will not persist out of the process thread...
    – dWitty
    Nov 30, 2020 at 10:52
  • 1
    Changing environment variables in a running process is always temporary. You can set environment variables by alling/spawning system commands/tools like setx under windows. Persisting them does not change the running enviroment in the process for that you have to restart the process. So you need both, set the variable as described above and in addition persist it with system tools/commands.
    – Hans Koch
    Dec 2, 2020 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.