7
votes

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...

3

3 Answers

15
votes

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();
9
votes

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();
8
votes

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 
});