Getting the installation directory from an installer
-
I have created a windows installer i VS.NET 2003 to install my application. The application consists of a windows service, a small winforms application and some dll's. The application installs and runs fine but only when I have hardcoded a path I have in a settings file. What I want to do is get the folder where I install the application and write that to the file when I install the application. Because that is what I want, the default path for this setting should be the folder where the application is installed. So is there any way to get that folder during the installation? I have tried using the Installer class but they alone doesnt seem to be enough. The only folder I can get from there is C:\windows\system32 which happens to be the current folder in the Installer class.
-
I have created a windows installer i VS.NET 2003 to install my application. The application consists of a windows service, a small winforms application and some dll's. The application installs and runs fine but only when I have hardcoded a path I have in a settings file. What I want to do is get the folder where I install the application and write that to the file when I install the application. Because that is what I want, the default path for this setting should be the folder where the application is installed. So is there any way to get that folder during the installation? I have tried using the Installer class but they alone doesnt seem to be enough. The only folder I can get from there is C:\windows\system32 which happens to be the current folder in the Installer class.
Check out the MsiGetProductInfo[^] function in the msi.dll . The
INSTALLPROPERTY_INSTALLLOCATION
property returnes the installation path. Sorry that I do not have any samples on how to do it in .NET and C#. But it should be fairly straight forward using pInvoke. /cadi 24 hours is not enough -
I have created a windows installer i VS.NET 2003 to install my application. The application consists of a windows service, a small winforms application and some dll's. The application installs and runs fine but only when I have hardcoded a path I have in a settings file. What I want to do is get the folder where I install the application and write that to the file when I install the application. Because that is what I want, the default path for this setting should be the folder where the application is installed. So is there any way to get that folder during the installation? I have tried using the Installer class but they alone doesnt seem to be enough. The only folder I can get from there is C:\windows\system32 which happens to be the current folder in the Installer class.
You could create a class library for the custom action of writing the installation path into your config file. Inside your InstallerClass you can use reflection to get the location the custom action is executed from (
Assembly.GetExecutingAssembly().Location
). This usually would be in the directory your service has been installed to. Regards, mav -
I have created a windows installer i VS.NET 2003 to install my application. The application consists of a windows service, a small winforms application and some dll's. The application installs and runs fine but only when I have hardcoded a path I have in a settings file. What I want to do is get the folder where I install the application and write that to the file when I install the application. Because that is what I want, the default path for this setting should be the folder where the application is installed. So is there any way to get that folder during the installation? I have tried using the Installer class but they alone doesnt seem to be enough. The only folder I can get from there is C:\windows\system32 which happens to be the current folder in the Installer class.
I managed to find a solution. I had a custom action in the installation to handle the Installer classes I had in my projects and there is a propery for a custom action called CustomActionData there. By setting the value of that parameter to
/installdir="[TARGETDIR]\"
I could get the installation directory in my Installer class with this code:this.Context.Parameters["installdir"]
. And that was all I needed. Took a while to find all parts of this solution and puzzle it together. I found one part of this solution at a time. Nowhere was it explained all the way. Thanks everybody for trying to help me!