|Often you need to get access to variables created during the installation process. One of the most common being the installation path or 'TARGETDIR'. This can be done by performing two steps.
In your deployment project, press the right mouse button on the project in the class view and select Custom Actions. You should see the four default states for the installer. Select the primary output for the Commit state.
In the properties window there is a property named CustomActionData, here you use name value pairs to define data to be accessible in your program. Setting the following property creates a variable named DIR with the target folder within it (Remember to include quotes as the path may contain spaces). This example also includes a trailing slash.
You can add additional variables by separating the values with commas.
In order to access the variable and do something during the installation you need to create a class which inherits from System.Configuration.Install.Installer. The following is a class written in vb.net which extends the commit of the installer to save a record in the registry of the target directory the app was installed to.
<RunInstaller(True)> Public Class ProjectInstaller
Dim strInstallLocation As String
Public Overrides Sub Commit(ByVal savedState As IDictionary)
'get the install location
strInstallLocation = Me.Context.Parameters.Item("DIR")
If strInstallLocation = Nothing Then
strInstallLocation = String.Empty
'always set the install dir
'default install function
Public Overrides Sub Install(ByVal savedState As IDictionary)
'function to set a registry value
Public Shared Function SetReportSettingsValue(ByVal Key As String, ByVal Value As String)
Dim RegKey As RegistryKey = Registry.LocalMachine
RegKey = RegKey.OpenSubKey("SOFTWAREReportSettings", True)
If Not RegKey Is Nothing Then
Heres some other useful urls on the subject.
Installer for a Windows Service
Exploiting .NET's Advanced Deployment Features