Jump to content


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.
Photo

Adding to PATH deletes the existing stuff


9 replies to this topic

premadhas

premadhas
  • Members
  • 6 posts

Posted 18 September 2003 - 15:37

Hi,
I want to add my applications path to the PATH variable.
For which the code is as follows:
nResult = RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);

if (nResult == 0) then
szKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
nResult = RegDBGetKeyValueEx(szKey, "Path", nvPath, szOldValue, nvSize);

if (nResult < 0) then
//MessageBox("Window PATH could not be retreived.", SEVERE);
//MessageBox("Current path could not be added to Windows PATH.", SEVERE);
RegDBSetKeyValueEx (szKey, "Path", REGDB_STRING_EXPAND, TARGETDIR, -1);
else
szNewValue = TARGETDIR + ";" + szOldValue;
nResult = RegDBSetKeyValueEx (szKey, "Path", REGDB_STRING_EXPAND, szNewValue , -1);
if (nResult < 0) then
MessageBox("Current path could not be added to Windows PATH.", SEVERE);
endif;
endif;
else
MessageBox("Current path could not be added to Windows PATH.", SEVERE);
//MessageBox("RegistryRoot could not be set.", SEVERE);
endif;

nResult = RegDBSetDefaultRoot(HKEY_CLASSES_ROOT);


It appends correctly to PATH and works fine for most of the cases. But overwrites the PATH in some cases. After repeated trials on various machines I observed that if the PATH contains C:\WINNT\System32 this happens? Is it correct? Can some one help me with a solution for this?

I'm using Win2K and IS6

Regards,
Prem.

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 19 September 2003 - 01:49

Hmm, well that code's a little messy and not the way I would go about, so tomorrow I'll give you some better/working code for doing this.
user posted image

premadhas

premadhas
  • Members
  • 6 posts

Posted 19 September 2003 - 05:21

Awaiting for your response.
I still have'nt got any clue on this...


Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 19 September 2003 - 14:41

CODE
#define ENVIRONMENT_KEY   "System\CurrentControlSet\Control\Session Manager\Environment"
#define ENVIRONMENT_PATH_VALUE "Path"


// FOR PATH SYSTEM VARIABLE, ADD REFERENCE TO THE INSTALL FOLDER
Disable(LOGGING);
bReboot = TRUE;
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
szRegKey = ENVIRONMENT_KEY;
if ( RegDBKeyExist(szRegKey) < 0 ) then
 szMsg = "ERROR: Failed to create multiple level keys!";
 Msg(szMsg, SEVERE);
 abort;
endif;
 
nvType = REGDB_STRING_EXPAND;
szRegStrName = ENVIRONMENT_PATH_VALUE;
RegDBGetKeyValueEx(szRegKey, szRegStrName, nvType, szRegStrValue, nvSize);
if ( !( szRegStrValue % TARGETDIR ) ) then
 szRegStrValue = szRegStrValue ^ ";";
 szRegStrValue = szRegStrValue + TARGETDIR ^ "\BIN";
 RegDBSetKeyValueEx(szRegKey, szRegStrName, nvType, szRegStrValue, -1);
endif;
Enable(LOGGING);

The Disable/Enable(LOGGING) is to prevent the uninstall from clearing out the path.
user posted image

premadhas

premadhas
  • Members
  • 6 posts

Posted 19 September 2003 - 15:49

It does'nt work. Same behaviour the path is overwritten with
;C:\MyTool\BIN
why bin has to be added?
I observed it happens in machines without PATH environment variable
Please provide me with more info
Thanks,
Prem.

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 19 September 2003 - 23:57

BIN doesn't have to be added. That was just an exact copy of what I do which has always worked for me and we have a separate BIN folder for our executables.

Also, for NT4/W2K/XP the path should _always_ exist. If it doesn't, then there's something wrong with those installations and ";C:\MyTool\BIN" is certainly what you'll end up with. Maybe some other uninstall emptied it by mistake. Maybe even your own uninstall since you weren't disabling the logging!!!

However, if it's Win9x/Me, then the path is controlled by a line in the autoexec.bat instead of this registry entry.

Edited by Taco Bell, 20 September 2003 - 00:00.

user posted image

premadhas

premadhas
  • Members
  • 6 posts

Posted 20 September 2003 - 06:47

Hi Tacho Bell,
Thanks for your valuable inputs.
My understanding of the problem goes like this:
The PATH variable gets loaded from three places
1) "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment"
2) Windows Environment Variable
3) One or many more "mysterious" places which I dont know. (Let me know your views on this)

I'm sure about this mysterious place because in the machines where I'm facing the problem,
there is no Windows Environment Variable path. Aftering deleting the key value "path" from
"HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment"
I still observed the PATH was "C:\WINNT\System32 and some other stuff"

In such a scenario if I try to do my applications installation which writes into
"HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment"
the mysterious path gets deleted.

Again if I uninstall my application, remove the key value "path" and re-start the machine
the mysterious PATH "C:\WINNT\System32 and some other stuff" appears!!!!

The problem still persists. Please help me!

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 20 September 2003 - 23:18

1 is the same as 2, and as I said, should ALWAYS exist. The Path registry value should never be deleted/removed.

It also takes a reboot or a broadcast message for any path changes to take affect.
user posted image

premadhas

premadhas
  • Members
  • 6 posts

Posted 24 September 2003 - 19:50

Thanks Tacho Bell,
Now I understood and got the problem solved


Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 24 September 2003 - 20:11

Great! Glad to hear it because I wasn't sure you were following me there. wink.gif
user posted image