Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically modifiy environment variables?

  • Windows 7.
  • It's for my own machine, so it doesn't matter if it requires admin rights or something.
  • Preferably in Python or .NET, but I can learn a bit of Win32 (C/C++) programming if it's necessary.
like image 908
Javier Avatar asked Jan 23 '10 02:01

Javier


1 Answers

if you want to permanently set environment variable, you can insert the new value into registry. eg with vbscript, add the path "c:\test" into PATH variable

Set WshShell = WScript.CreateObject("WScript.Shell")
strReg = "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path"
strSetting = WshShell.RegRead(strReg)
strNewSetting = strSetting&";c\test"
WshShell.RegWrite strReg, strNewSetting

So, if you use Python or other languages, you can do the same thing using your language's own api/modules to read and write registry

like image 164
ghostdog74 Avatar answered Sep 28 '22 10:09

ghostdog74