Adding a path to the env. variable PATH
Posted 31 August 2004 - 00:17
My problem is that I need to add a specific folder to the environment variable PATH.
Could someone please tell me how I can modify the environment variable "path" programmatically?
There is a GetEnvVar(), but there is no SetEnvVar()
Posted 31 August 2004 - 07:47
if you don't want to use the IDE functions of InstallShield to add your path, you could use the Kernel32 function "SetEnvironmentVariable" to add it.
prototype BOOL KERNEL32.SetEnvironmentVariable(BYVAL STRING, BYVAL STRING);
if (GetEnvVar ( "Path", svPath)==0) then
if !(svPath % svYourPath) then
svPath = svPath + ";" + svYourPath;
if (!SetEnvironmentVariable("Path", svPath)) then
MessageBox ("Could not add path to environment!", WARNING); endif;
MessageBox("Error retrieving environment!", WARNING);
Hope it helps.
Edited by Jochen, 31 August 2004 - 07:55.
Posted 31 August 2004 - 16:12
Thanks a lot for your reply. I posted the message because I could not find any function in InstallShield that adds the path. Am I wrong? Is there an API that I can use to add a path ?
The code block that you have sent solves my problem, but just curious to know if there is an easier way that I was unable to find.
Posted 01 September 2004 - 09:58
IMHO in Install Script there is no function to set the environment variable.
The only way to set the variable is to use the Kernel32 function I posted in my previous message. This is some kind of API function.
The other possibilities to set the environment variable are to use the Windows Installer environment table or the environment variables view under system configuration in the InstallShield user interface (only if you are using an InstallScript MSI Project). Or you can edit the registry (depends on the OS) under HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment but I'd not recommend this.
Posted 01 September 2004 - 16:20
Your first solution works perfectly, and I am sticking to that
Thanks a lot!!