Page 1 of 1
Changing Windows Environmental Variables
Posted: Sat Jun 02, 2012 12:12 am
by Alric
I'm trying to write a simple app that will change/set window's environment variables. Something like window's "Setx" command.
If there a command to do this?
In running under Windows 7 if that matters.
Thanks
Re: Changing Windows Environmental Variables
Posted: Sat Jun 02, 2012 6:41 am
by shaosean
Simplest way would be to use the
shell function and make the call out to the command line
setx command..
Re: Changing Windows Environmental Variables
Posted: Sat Jun 02, 2012 7:50 pm
by SirWobbyTheFirst
Hi Alric.
If you are just changing the environment variables for your applications process only (IE. Internet Explorer and other Applications keep the standard ones issued by Windows) then you can simply do the following:
Code: Select all
// Append the applications default folder to the %Path% variable.
Put $Path & ";" & The DefaultFolder Into $Path
If however you want to change it on a global scale then you can look in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment for a list of environment variables Windows creates at boot up. This area is present as far back as Windows NT 4.0 I believe, you would need to find out yourself for earlier versions, so compatibility will be ensured.
BUT!!!
Be warned this area is dangerous and can brick your system, you'll also need to set your application to elevate with UAC otherwise you'll be met with an Access Denied error. Additionally, the users own environment variables are stored in HKEY_CURRENT_USER\Environment, again be careful as you could potentially brick the users profile and/or applications if you mess around too much.
Source: My own, I've did the bricking in the past in order to find it out myself. RIP to all those Windows installations.

Re: Changing Windows Environmental Variables
Posted: Sat Jun 02, 2012 8:13 pm
by Alric
Thanks for the info. The shell command looks promising, especially since I'm currently using batch files to set the environment variables.
I'll give it a try and see what happens.