Search code examples
c#windows-installerworking-directory

Locate original location of installer exe on disk from within the installer c#


I have an MSI installer with a c# custom action running at the end that executes an sql script before the installer exits. We decided the best way to do this is to stick the sql script file in the same directory as the MSI file and have it load the script that way.

The problem is, the installer copies itself to Windows\system32 and then executes from there, so I cannot find the original directory in order to execute the script file. Any help or ideas would be appreciated!


Solution

  • Does OriginalDatabase property help you?

    The Windows Installer sets the OriginalDatabase property to the path of the installation database used to launch the installation. If the installation is launched from a command line, the value depends on whether the recache package option (the -v flag) is present in the REINSTALLMODE property.