Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron get or set Environment variables in Windows?

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 ?

like image 736
Devid Avatar asked Nov 08 '17 16:11

Devid


1 Answers

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.

like image 77
Hans Koch Avatar answered Nov 09 '22 20:11

Hans Koch