0

I am trying to install MSI through code, and I came across this solution Programatically installing MSI packages

Code:

 public static void Install()
 {
    try 
    {
        Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");
        Installer installer = (Installer)Activator.CreateInstance(type);
        installer.InstallProduct("D:\\Applications\\TortoiseSVN-1.9.3.27038-x64-svn-1.9.3", "ACTION=INSTALL");
    } 
    catch(Exception e)
    {
        Utilities.showErrorMessageBox(e.Message);
    }
 }

The exception I get has this non descriptive message: {"InstallProduct,PackagePath,PropertyValues"}

I don't know what sense to make of it. I have also tried various combinations of PropertyValues but to no avail.

Can someone explain the reason behind this error?

EDIT

Using the following works:

System.Diagnostics.Process.Start("D:\\Applications\\TortoiseSVN-1.9.3.27038-x64-svn-1.9.3.msi");

So, is this method as fine as using the Installer?

Community
  • 1
  • 1
Furqan Tariq
  • 73
  • 1
  • 12

1 Answers1

0

IMO the simplest way is to call the direct API MsiInstallProduct and inspect the result to see what happened. The P/Invoke signature is straightforward, and it's the end of that post you mentioned.

Programatically installing MSI packages

The issue with many other attempts I see is the introduction of an unnecessary COM layer. So you can fail in that COM layer unless the environment is correct (threads, apartments and whatever else may be required), and failure obfuscates the simple error that MsiInstallProduct will return (as in your case).

Close inspection of the exception (perhaps an inner exception) might show an HRESULT or integer result from MsiInstallProduct, maybe 4 digits from this list:

https://msdn.microsoft.com/en-us/library/aa368542(v=vs.85).aspx

Otherwise, set the Windows Installer logging policy to create a verbose log:

https://support.microsoft.com/en-us/kb/223300

with voicewarmupx in the logging string and then look in %TEMP% for the MSIxx.log file. This assumes that your environment isn't causing the problem. If you're running the code from something like the local system account there are opportunities for failure if the MSI tries to access items like the Desktop for the local system account. You'll need that log to see what's going on. If the MSI file has no UI and requires elevation then it won't ask for elevation and will fail. If it's got an external CAB file maybe it can't find it, then failure. If it's running from a mapped drive location then it can fail too. So this isn't only about the code because the environment matters. There are many failure points which are nothing to do with the coding.

Community
  • 1
  • 1
PhilDW
  • 20,260
  • 1
  • 18
  • 28