cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Hannes
Level 3

System variable PATH

Hello!

I need to add the installation directory of my programm () to the environment system variable PATH.

I tried a lot of, but nothing I do works, so I hope that anybody can help me.

thanks, Hannes
Labels (1)
0 Kudos
(7) Replies
esiemiat
Level 9

What project type are you using? Pure InstallScript, Basic MSI, or InstallScript MSI.
0 Kudos
Hannes
Level 3

I use the pure InstallScript type.
0 Kudos
esiemiat
Level 9

In an InstallScript project you create\modify an environment variable by writing to the registry. So first I would use the GetEnvVar function to retrieve the current path variable. Then add your path to the string. Finally I would use RegDBSetKeyValueEx to write your path back to the registry. The following code has not been tested but will hopefully point you in the right direction.


sRegKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";

GetEnvVar("PATH", svEnvVar);
sNewPath= svEnvVar + NEW_PATH_FOLDER";

nResult = RegDBSetKeyValueEx(sRegKey, "PATH", REGDB_STRING_EXPAND, sNewPath, -1);
0 Kudos
Hannes
Level 3

Thanks! It works very well. But I have one new problem, that every path-entry exits two times in the new PATH environment variable.

I think that the reason for this is, that an other program set also a PATH user variable and if I read the PATH variable, both variables (user and system environment variable) will be read out. So my questions: Can I tell them to read only the system variable?

Thanks, Hannes
0 Kudos
esiemiat
Level 9

Try parsing the path to see if the path you are adding is already there. If it is then you do not need to add your path.

Your other option is to replace the GetEnvVar with a registry read of the same key you are saving the path back to. This will ensure that you are only reading the system variable, but will not ensure that the path is not in the user's path.
0 Kudos
m_rudolph
Level 6

I have a header/rul combo from InstallSite.org that does this for you. Have had great success using it. I attached it for you if you'd like to try it out.

I tried searching the site for it so you could grab it, but couldn't find it. There's another one there now (search by 'Handle PATH Environment on NT').
0 Kudos
Hannes
Level 3

I use windows XP.

my code looks like:

sRegKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);

RegDBGetKeyValueEx(sRegKey,"PATH", nvType, sRegCurrentVal, nvSize);

This code only returns me the current installation path (TARGETDIR) and not the entry in the PATH environment variable.

Hannes
0 Kudos