First off, everyone thanks for the help.....
i need help trying to add to the envirnment variable PATH.
i used the function that is in examples to find a file in PATH but now i need help on how to add one.
anyone's assistance is greatly appreciated.
thanks again,
KevSev
This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.

adding an environment variable to PATH
Started by
KevSev
, Mar 19 2002 17:10
4 replies to this topic
Posted 19 March 2002 - 22:30
I feel lazy today, so I'll just tell you that there have been a couple discussions on this topic before, so just do a search for the keyword "path" and I'm sure you'll find what you're looking for.

Posted 20 March 2002 - 14:24
Here is how I add a value to the path variable on NT and WIN2000. Make sure you disable logging before creating the entry because it may remove the whole key when you uninstall.
Global Declarations
#define WM_SETTINGCHANGE 0x001A
#define HWND_BROADCAST 0xffff
Local Declaration
POINTER pEnv
Disable (LOGGING);
sKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
sName = "Path";
RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
//Check to see if the key exists
if (RegDBGetKeyValueEx(sKey, sName, nType, sValue, nSize) < 0) then
//If it doesn't, create it and if successful, broadcast the change
if (RegDBSetKeyValueEx(sKey, sName, REGDB_STRING_EXPAND, gsAppExePath, -1) = 0) then
sEnv = "Environment";
pEnv = &sEnv;
sendMessage (HWND_BROADCAST, WM_SETTINGCHANGE, 0, pEnv);
endif;
else
if (RegDBSetKeyValueEx(sKey, sName, nType, sValue + ";" + gsAppExePath, -1) = 0) then
//if it does exist then add the path to the end of the value and if successful, broadcast the change
sEnv = "Environment";
pEnv = &sEnv;
SendMessage (HWND_BROADCAST, WM_SETTINGCHANGE, 0, pEnv);
endif;
endif;
Enable(LOGGING);
HTH
BobT
Global Declarations
#define WM_SETTINGCHANGE 0x001A
#define HWND_BROADCAST 0xffff
Local Declaration
POINTER pEnv
Disable (LOGGING);
sKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
sName = "Path";
RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
//Check to see if the key exists
if (RegDBGetKeyValueEx(sKey, sName, nType, sValue, nSize) < 0) then
//If it doesn't, create it and if successful, broadcast the change
if (RegDBSetKeyValueEx(sKey, sName, REGDB_STRING_EXPAND, gsAppExePath, -1) = 0) then
sEnv = "Environment";
pEnv = &sEnv;
sendMessage (HWND_BROADCAST, WM_SETTINGCHANGE, 0, pEnv);
endif;
else
if (RegDBSetKeyValueEx(sKey, sName, nType, sValue + ";" + gsAppExePath, -1) = 0) then
//if it does exist then add the path to the end of the value and if successful, broadcast the change
sEnv = "Environment";
pEnv = &sEnv;
SendMessage (HWND_BROADCAST, WM_SETTINGCHANGE, 0, pEnv);
endif;
endif;
Enable(LOGGING);
HTH
BobT
Posted 21 March 2002 - 03:01
OKay, that'll do the job, but couple things I wanted to point out:
1. I know some will probably disagree with me in this approach, but I _THINK_ a broadcast is only necessary if your setup doesn't already require a reboot. Can anyone back me up on this?
2. If the PATH system variable doesn't already exist, then the OS has problems. Particularly if it's WINNT/W2K.
3. Your code here doesn't check if your App. Path is already in PATH, so each time you run your setup your unnecessarily appending your install directory.
1. I know some will probably disagree with me in this approach, but I _THINK_ a broadcast is only necessary if your setup doesn't already require a reboot. Can anyone back me up on this?
2. If the PATH system variable doesn't already exist, then the OS has problems. Particularly if it's WINNT/W2K.
3. Your code here doesn't check if your App. Path is already in PATH, so each time you run your setup your unnecessarily appending your install directory.

Posted 21 March 2002 - 10:27
TacoBell00:
About (1) : true, a broadcast is (only) needed to let running applications know that the environment has been changed. Since the environment is set anew during startup of windows, the broadcast isn't needed if you will reboot anyway. Note that some applications are not able to process a broadcast and hence won't receive the updated environment. Most noticably is the IS IDE. This means that if you run an install directly with setup.exe, the broadcast will get processed in your project, but if you run it from the IDE, it won't. (don't you just love IS, sometimes)
BobT & KevSev:
If you are running winNT/2000: There are scripts in the 'IS5/6 Samples > Operation System' which will handle your PATH for you.
Ide
About (1) : true, a broadcast is (only) needed to let running applications know that the environment has been changed. Since the environment is set anew during startup of windows, the broadcast isn't needed if you will reboot anyway. Note that some applications are not able to process a broadcast and hence won't receive the updated environment. Most noticably is the IS IDE. This means that if you run an install directly with setup.exe, the broadcast will get processed in your project, but if you run it from the IDE, it won't. (don't you just love IS, sometimes)
BobT & KevSev:
If you are running winNT/2000: There are scripts in the 'IS5/6 Samples > Operation System' which will handle your PATH for you.
Ide