cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Pilgrim

Setting the System Path Variable

Hi,

I'm trying to add a path to the windows system environment variable:


prototype INT KERNEL32.SetEnvironmentVariable(BYVAL STRING, BYVAL STRING);

function AddPath(svYourPath)

string svPath, , svSubStr, szAppPath;

begin

if (GetEnvVar ( "Path", svPath)==0) then

if !(svPath % svYourPath) then

if (StrSub(svSubStr, svPath, StrLengthChars(svPath) - 1, 1) = 1) then

if (svSubStr = ';') then
svPath = svPath + svYourPath;
else
svPath = svPath + ";" + svYourPath;
endif;

endif;

endif;

if (SetEnvironmentVariable("Path", svPath) = 0) then
MessageBox ("Could not add path to environment!", WARNING);
endif;

else
MessageBox("Error retrieving environment!", WARNING);
endif;

end;



I'm testing this on a Windows 7 Professional 64-bit with UAC turned off. The code seems to execute without issue when I step through with the debugger but the system path does not get updated...

Am I going about this the wrong way? Does anyone have any ideas about this?

Thanks
Labels (1)
0 Kudos
4 Replies
Highlighted
Pilgrim

Re: Setting the System Path Variable

Look at:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682653(v=vs.85).aspx

SetEvironmentVariable only modifies the current processes copy of the environment variables. The above doc says to persist a change to the registry.

I think at one time I used the code at:
see www.installsite.org > InstallScript Samples > Operating System > Handle PATH Environment on NT.

But that was a while ago and I do not know how it would play on Win 7.
0 Kudos
Highlighted
Pilgrim

Re: Setting the System Path Variable

Depending on what variant of InstallShield and what project you're using, InstallShield should have a built-in tool to help you set any environment variable. The tool will also take care of your rollback and uninstall actions.

For my own project, I was able to add a directory to the system wide Path variable. For reference, I have the Professional edition and am developing an InstallScript MSI project.
0 Kudos
Highlighted
Pilgrim

Re: Setting the System Path Variable

jhrlim wrote:
Depending on what variant of InstallShield and what project you're using, InstallShield should have a built-in tool to help you set any environment variable.

I am using Installshield 2012 Spring and this is a Installscript project. I was not able to find anything built into Installshield to set an environment variable... the closest thing I could find was GetEnvVar.

I am going to try setting the path in the registry like phill_mn suggests.

Thanks
0 Kudos
Highlighted
Pilgrim

Re: Setting the System Path Variable

A link to this example is at the bottom of the help doc for GetEnvVar
http://kb.flexerasoftware.com/doc/Helpnet/installshield15helplib/GetresEnv_variable_example.htm
0 Kudos