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 ?

Devid
  • 1,823
  • 4
  • 29
  • 48
  • See https://stackoverflow.com/a/54215867/327074, that uses a batch file wrapper to the exe – icc97 Jun 22 '23 at 21:13

1 Answers1

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.

Hans Koch
  • 4,283
  • 22
  • 33
  • 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 '20 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 02 '20 at 04:04