10-21-2008 01:02 PM
Solved! Go to Solution.
10-21-2008 01:19 PM - edited 10-21-2008 01:26 PM
Normally you use the command "set" to set an environment variable through the command line. You can use System Exec to call "set". However, the problem you're going to have is that the existence of the variable is limited to the existence of the command window in which you run the command. This means that once you complete the execution of System Exec that sets the variable it's gone. If there's another application which is supposed to manipulate this environment variable (and it sounds like that's what you're trying to have available), then that app won't find it. You would need to set the variable as a system environment variable. The command setx can do that, though setx is not normally distributed with Windows. You need to get the Windows Resource Kit to use it. Basically what that command does is add/remove keys from the registry (specifically HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment). Thus you can use the registry VIs to add/remove keys from there.
EDIT: You can get setx from here.
10-21-2008 01:53 PM - edited 10-21-2008 01:56 PM
Be aware that the solution by smercurio_fc is restricted to users having enough rights to set system variables. Normally you need to have administrator rights to do that. Restricted users are not allowed to make changes in HKLM of the registry.
There is another set of environment variables which are related to the current user. These environment variables are located under HKEY_CURRENT_USER\Environment. On the other hand you need to logoff and logon until this setting will be seen (tested with the command prompt).
10-21-2008 02:06 PM
After a second test I wanted to edit my previous post, but time has passed.
The previous test was made with regedit and the command prompt. Next I used the control panel to set the environment variable and it will take effect immediatly without the need to logoff/logon. I think there is a Windows API call to set and propagate the environment variable.
10-21-2008 02:23 PM
Thanks to both smercurio_fc and Waldemar.
Summary:
Yes, a system variable is what I want to use and I want to set it with a LV.exe which will then complete and close, and then check said variable with a separate program. It sounds like I can use the registry VIs to set system level variables (or create a key to check, then remove) but there may be a restriction based on user privileges.
I think I can get around the user privileges but I've never used the registry VIs. Does anyone know of literature on this subject?
phy508
10-21-2008 02:33 PM
10-21-2008 06:03 PM
10-23-2008 06:42 AM
10-23-2008 06:51 AM - edited 10-23-2008 06:52 AM
10-23-2008 06:57 AM
I guess, in my fatigue clouded brain, I focused on only the registry related part of the thread, seeing now that the primary question asked was regarding Windows enviroment variables. Sorry. I will repost with my own Subject, and not further hijack this thread.
Putnam