|
I have a Windows Installer Setup project as part of my VS2005 solution, and was wondering if there was any way I could interact with Environment Variables from within this project? Specifically, I was looking at a way to update the PATH variable on an install, and then remove the added entry during un-install. I was hoping there would be a quick and easy way of doing this. The Setup project has a Registry Editor, and I was expecting something similar to that like the Environment Variables Editor.. No such luck!
Thx!
|
| Ameya Barve Thursday, December 08, 2005 12:48 AM |
The Setup projects in Visual Studio don't have anything specificially exposed for reading or writing to Environment variables. You can do this in one of two ways: - Write some code that does it and use it as a custom action.
- Check the Windows Installer SDK documentation on MSDN and see if you can do it there. If so, write a VBScript (or other script or application) that modifies the built .MSI to add the entries needed to do this. Then hook up this program/script to the Post Build events of a setup project so it adds the entries each time you build setup.
Either way is a little bit of work, but once figured out, should work fine. |
| David Guyer MSFT Thursday, December 08, 2005 9:16 PM |
Bump.
Anyone?
|
| Ameya Barve Thursday, December 08, 2005 6:29 PM |
The Setup projects in Visual Studio don't have anything specificially exposed for reading or writing to Environment variables. You can do this in one of two ways: - Write some code that does it and use it as a custom action.
- Check the Windows Installer SDK documentation on MSDN and see if you can do it there. If so, write a VBScript (or other script or application) that modifies the built .MSI to add the entries needed to do this. Then hook up this program/script to the Post Build events of a setup project so it adds the entries each time you build setup.
Either way is a little bit of work, but once figured out, should work fine. |
| David Guyer MSFT Thursday, December 08, 2005 9:16 PM |
| David Guyer MS wrote: | The Setup projects in Visual Studio don't have anything specificially exposed for reading or writing to Environment variables. You can do this in one of two ways: - Write some code that does it and use it as a custom action.
- Check the Windows Installer SDK documentation on MSDN and see if you can do it there. If so, write a VBScript (or other script or application) that modifies the built .MSI to add the entries needed to do this. Then hook up this program/script to the Post Build events of a setup project so it adds the entries each time you build setup.
Either way is a little bit of work, but once figured out, should work fine. |
|
Thx, I already knew about Custom Actions, in fact that's what I had originnally decided to do, but I thought I'd check first, because it seems like a bit of an overkill to create a custom DLL just to update the environment variables. I'll stick with a Custom Action. |
| Ameya Barve Monday, December 12, 2005 9:36 PM |
Hey,
Can you post a sample code in your dustom DLL for updating the environment variables
TIA
|
| NURBY Nerd Tuesday, February 21, 2006 8:42 PM |
Windows Installer has built in capabilities for that purpose (the Environment table), butVisual Studio doesn't expose it. IMHO it's not a good idea to re-invent native Windows Installer functionality in your own DLL just to circumcvent limitations in your authoring tool. Therefore I would prefer a VBScript to post-process the built .msi file (or use an msi authoring tool that supports Windows Installer's environment table).
If you decide to go the DLL route then make sure you also handle rollback (aborted install) and uninstall properly. |
| Stefan Krueger Wednesday, February 22, 2006 11:25 AM |
So, will it work if I just copy the assemblies to a folder (say application folder) by adding assemblies in the file system editor and the windows installer will update the environment table...
TIA
|
| NURBY Nerd Wednesday, February 22, 2006 2:41 PM |
If you want to updateenvironment variables like PATH you need to tell Windows Installer which variable should be set or updated in which way. For this purpose there's a table called Environment that you can add to the .msi file (an .msi file is a relational database). However you cannot do this with Visual Studio. |
| Stefan Krueger Wednesday, February 22, 2006 2:49 PM |
Hey Stefan.. thanks for the info..
I was wondering if this was a good idea. I can update the environment variables using a batch file with SET command.
In Custom Actions > Install if I can call this batch file (.bat or .exe) which will set the environmental variables .
But then again, the path of these dll files (in applications folder) is determined run time acc to user input. I have a registry entry which gives me the path. can I get the path from registry and use it in setting the env. variable? (I dont know if this can be done)
also Custom Actions> Uninstall will have a reverese batch file
any idea if that will work
TIA |
| NURBY Nerd Wednesday, February 22, 2006 11:04 PM |
I believe that would only be effective for the session in which the bat file runs, not globally, and would not be persistent. You can try it by simply opening a DOS box and running your bat there, then open another DOS box and check the environment. |
| Stefan Krueger Friday, February 24, 2006 4:20 PM |
I was having the same problem. To accomplish setting a PATH Environment variable I used WinINSTALL LE to edit my .msi file and under 'Advertising' \ 'Environment' I added a new variable.
Variable = PATH and Value = [TAGETDIR] with the following options. Set Only, Remove - Uninstall & Append.
I have tested installing (default and altered install paths) and uninstalling and it works great every time.
NOTE: When you recompile this will be wiped out so it must be the last thing you do before deploying.
Kenny |
| KYoung Friday, May 05, 2006 1:13 PM |