Hi all,
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()
Thanks,
Vishwa
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 a path to the env. variable PATH
Started by
vishwa
, Aug 31 2004 00:17
4 replies to this topic
Posted 31 August 2004 - 07:47
Hi vishwa,
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.
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.
CODE |
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; endif; else MessageBox("Error retrieving environment!", WARNING); endif; |
Hope it helps.
Regards,
Jochen
Edited by Jochen, 31 August 2004 - 07:55.
Posted 31 August 2004 - 16:12
Hi Joshen,
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.
Thanks,
Vishwa
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.
Thanks,
Vishwa
Posted 01 September 2004 - 09:58
Hi Vishwa,
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.
Regards,
Jochen
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.
Regards,
Jochen
Posted 01 September 2004 - 16:20
Hi Jochen,
Your first solution works perfectly, and I am sticking to that
Thanks a lot!!
- Vishwa
Your first solution works perfectly, and I am sticking to that
Thanks a lot!!
- Vishwa