7

I am trying to run an MSI file from C# using the Proces.Start method. The MSI file is fine, because I can run that normally, but when I try to run the MSI file within some C# code I receive the following error.

"This installation package could not be opened. Verify that the package exists, and that you can access it, or contact the application vendor to verify that this is a valid windows installer package"

Below is the code that I am using to run the MSI file...

Process p = Process.StartApplication.StartupPath  "/Packages/Name.msi");

p.WaitForExit();   

How can I fix this problem?


OK, I got it now. I just changed it to run the setup.exe file that is generated with the MSI file, instead of the running the MSI file...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cwisking
  • 129
  • 1
  • 7

3 Answers3

15

msi files cannot run on their own. If you double click on them, Windows will start

msiexec /i PathToYour.msi

Did you try to do that explicitly?

Example: (Courtesy @Webleeuw)

Process p = new Process();
p.StartInfo.FileName = "msiexec";
p.StartInfo.Arguments = "/i PathToYour.msi";
p.Start();
saschabeaumont
  • 22,080
  • 4
  • 63
  • 85
Benjamin Podszun
  • 9,679
  • 3
  • 34
  • 45
9

Addition to question poster's comment on Benjamin's answer:

Process p = new Process();
p.StartInfo.FileName = "msiexec";
p.StartInfo.Arguments = "/i PathToYour.msi";
p.Start();
Webleeuw
  • 7,222
  • 33
  • 34
  • 3
    Doesn't work for me. It is showing the windows installer box with the instructions for some reason. – alice7 Sep 13 '11 at 15:47
  • I ran into the same issue. See Dirk Vollmar's solution below, which worked for me. – batpox Feb 04 '19 at 01:03
8

It is also possible to execute the .msi file directly with the associated application. This happens when you set UseShellExecute to true:

Process.Start(new ProcessStartInfo() 
{ 
    FileName = @"c:\somepath\mySetup.msi", 
    UseShellExecute = true 
});
johnny 5
  • 19,893
  • 50
  • 121
  • 195
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316