Changing Windows Environmental Variables

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Alric
Posts: 2
Joined: Sun Feb 12, 2012 9:16 am

Changing Windows Environmental Variables

Post by Alric » Sat Jun 02, 2012 12:12 am

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

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Changing Windows Environmental Variables

Post by shaosean » Sat Jun 02, 2012 6:41 am

Simplest way would be to use the shell function and make the call out to the command line setx command..

SirWobbyTheFirst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 239
Joined: Tue Jun 30, 2009 11:15 pm

Re: Changing Windows Environmental Variables

Post by SirWobbyTheFirst » Sat Jun 02, 2012 7:50 pm

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. :D

Alric
Posts: 2
Joined: Sun Feb 12, 2012 9:16 am

Re: Changing Windows Environmental Variables

Post by Alric » Sat Jun 02, 2012 8:13 pm

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.

Post Reply

Return to “Windows”