tags:

views:

405

answers:

4

Hi all,

I am trying to run an msi from c# using the Proces.Start method. the Msi is fine because i can run that normally. but when i try and run the msi 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...

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

p.WaitForExit();   

Any ideas?

Thanks

+5  A: 

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?

Benjamin Podszun
forgive me for being retarded, but how would i do that with the Process.Start?
Cwisking
See Webleeuw's answer for a complete sample.
Benjamin Podszun
+5  A: 

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
A: 

ok i got it now. having one of those blue days i guess... i just changed it to run the setup.exe that is generated with the msi, instead of the running the msi...

thanks for the help tho :)

Cwisking
Welcome to SO :-) Unlike as in other forums, such remarks should normally not be added as an "answer" on SO (as it is not an answer to the question). Just make it a comment. And also don't forget to accept an answer if it actually solves your problem.
0xA3
And please note that there is actually a difference between running setup.exe (the so-called bootstrapper) and the .msi file generated. Normally you should prefer setup.exe over the .msi file. The setup.exe will install additional pre-requisites that might be required to run your msi/application (typically these pre-requisites include Windows Installer, .NET Framework, SQL server or any additional software required by your application). You can configure these pre-requisited in the properties of your Setup and Deployment project.
0xA3
+2  A: 

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