Setting environment variables from installer?
-
I am creating a msi installer for a command line program I have written in c#. I would like the user to be able to just type the program name from anywhere on the file system, and have the program run. Basically, I need to alter the PATH environment variable to include the installation directory. I have spent some time looking for solutions, and I haven't been able to find any thing definitive. Options I have found include: -Editing the registry from the installer: requires reboot, and deletes entire path variable on uninstall. -calling a Custom Action DLL to edit the path. DLL must be written in c++ (is that correct?). Can't uninstall? -write a vbs script to be run by the installer and set the path. (I don't know VBS script) -provide instructions to the user to tell them how to edit their path : not very user friendly. However, none of these seem like good options. I understand some of the reasons why setting an environment variable is not really a good idea, but surely this is something that needs to be done quite often. So, any suggestions or ideas? mike c
-
I am creating a msi installer for a command line program I have written in c#. I would like the user to be able to just type the program name from anywhere on the file system, and have the program run. Basically, I need to alter the PATH environment variable to include the installation directory. I have spent some time looking for solutions, and I haven't been able to find any thing definitive. Options I have found include: -Editing the registry from the installer: requires reboot, and deletes entire path variable on uninstall. -calling a Custom Action DLL to edit the path. DLL must be written in c++ (is that correct?). Can't uninstall? -write a vbs script to be run by the installer and set the path. (I don't know VBS script) -provide instructions to the user to tell them how to edit their path : not very user friendly. However, none of these seem like good options. I understand some of the reasons why setting an environment variable is not really a good idea, but surely this is something that needs to be done quite often. So, any suggestions or ideas? mike c
The Windows Installer Environment table has a good solution for setting environment variables, but unfortunately the Visual Studio deployments projects don't give you a way to author entries in the appropriate table. You'll have to use some other tool to author that part of your setup. If you've got money to spend, there are several more sophisticated setup packages that give you a GUI authoring tool and access to this. I've also done things like this by using the Orca tool (part of the Windows Installer SDK portion of the Platform SDK) to create a merge module (.MSM file) which I include into a setup otherwise authored in Visual Studio's deployment project tool. This will take you more learning & effort, but it's a free download Burt Harris
-
The Windows Installer Environment table has a good solution for setting environment variables, but unfortunately the Visual Studio deployments projects don't give you a way to author entries in the appropriate table. You'll have to use some other tool to author that part of your setup. If you've got money to spend, there are several more sophisticated setup packages that give you a GUI authoring tool and access to this. I've also done things like this by using the Orca tool (part of the Windows Installer SDK portion of the Platform SDK) to create a merge module (.MSM file) which I include into a setup otherwise authored in Visual Studio's deployment project tool. This will take you more learning & effort, but it's a free download Burt Harris
Thanks for the tip. So, I would basically create some seperate code (in c#?) which would manipulate the environment variables using the Environment Table. Basically, I want to add my application install directory to the path during installation, and remove it if the app is uninstalled. Btw, I jsut download and installed the SDK you mention above, but I cant seem to find the orca tool you referenced. thanks for the leads... mike c
-
Thanks for the tip. So, I would basically create some seperate code (in c#?) which would manipulate the environment variables using the Environment Table. Basically, I want to add my application install directory to the path during installation, and remove it if the app is uninstalled. Btw, I jsut download and installed the SDK you mention above, but I cant seem to find the orca tool you referenced. thanks for the leads... mike c
mikechambers wrote: So, I would basically create some seperate code (in c#?) which would manipulate the environment variables using the Environment Table. The easiest way would be to use Orca to add the environment variables to the Environment table of your Windows Installer database after you create it with the VS .NET deployment thing. mikechambers wrote: Btw, I jsut download and installed the SDK you mention above, but I cant seem to find the orca tool you referenced. Are you sure you installed the Windows Installer section of the Platform SDK? Because I have it on my computer in the Program Files\Orca9x directory (for you it would be Program Files\OrcaNT, I believe). Note that it is not in the Microsoft SDK\bin directory, but the installer for it is there.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi -
mikechambers wrote: So, I would basically create some seperate code (in c#?) which would manipulate the environment variables using the Environment Table. The easiest way would be to use Orca to add the environment variables to the Environment table of your Windows Installer database after you create it with the VS .NET deployment thing. mikechambers wrote: Btw, I jsut download and installed the SDK you mention above, but I cant seem to find the orca tool you referenced. Are you sure you installed the Windows Installer section of the Platform SDK? Because I have it on my computer in the Program Files\Orca9x directory (for you it would be Program Files\OrcaNT, I believe). Note that it is not in the Microsoft SDK\bin directory, but the installer for it is there.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhithanks. It is not there, so perhaps I installed the wrong sdk. I realized that I can have the installer launch an executable or call a dll (written in c#?). So, i might just put the code I need in there. mike c
-
I am creating a msi installer for a command line program I have written in c#. I would like the user to be able to just type the program name from anywhere on the file system, and have the program run. Basically, I need to alter the PATH environment variable to include the installation directory. I have spent some time looking for solutions, and I haven't been able to find any thing definitive. Options I have found include: -Editing the registry from the installer: requires reboot, and deletes entire path variable on uninstall. -calling a Custom Action DLL to edit the path. DLL must be written in c++ (is that correct?). Can't uninstall? -write a vbs script to be run by the installer and set the path. (I don't know VBS script) -provide instructions to the user to tell them how to edit their path : not very user friendly. However, none of these seem like good options. I understand some of the reasons why setting an environment variable is not really a good idea, but surely this is something that needs to be done quite often. So, any suggestions or ideas? mike c
Mike, I'd recommend that you don't modify the PATH variable at all - the path has a limited size and a lot of installers edit the PATH unnecessarily. Instead, setup a registry subkey under the App Paths key:
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths]
Easy to delete at uninstall time too. You set the key name to your .exe name (no path) and set the default unnamed value to the full path to the .exe; optionally you can also set a
Path
value containing the extra directories needed by that executable (really useful for multiple applications that refer to common libraries). Beware though that if your executable name is something obvious that may have been used by someone else (e.g. "msdev.exe") you may end up overwriting the existing key. BTW, I'd also recommend that if you do install shared libraries somewhere then store that path in the registry (under HKLM) to allow other installers to find them, rather than hardcoding installation folders. Regards, John Bates. -
Mike, I'd recommend that you don't modify the PATH variable at all - the path has a limited size and a lot of installers edit the PATH unnecessarily. Instead, setup a registry subkey under the App Paths key:
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths]
Easy to delete at uninstall time too. You set the key name to your .exe name (no path) and set the default unnamed value to the full path to the .exe; optionally you can also set a
Path
value containing the extra directories needed by that executable (really useful for multiple applications that refer to common libraries). Beware though that if your executable name is something obvious that may have been used by someone else (e.g. "msdev.exe") you may end up overwriting the existing key. BTW, I'd also recommend that if you do install shared libraries somewhere then store that path in the registry (under HKLM) to allow other installers to find them, rather than hardcoding installation folders. Regards, John Bates.thanks for the suggestion on app path. I had looked into that, but unfortunately, the app path is not search when commands are run from the command line. only from the run window. mike c