1

When i try to run a msi using System.Process.Start("test.msi") in a vb app i get the following error.

The installation package could not be opened. Contact application vendor...

Msi file works fine when double clicked, tried System.Process.Start with text files and exe files and they work fine, problem only with msi

files. Running vista. Also tried xp but no luck

Thanks

tambo
  • 11
  • 1
  • 2
  • 1
    The heart of the problem is that MSI's are not executables. You can double click them to open because all versions of Windows have the MSI utility built-in and it knows to open .msi with the MSI utility – Samuel Nov 04 '10 at 13:01
  • 1
    @Samuel, that's not quite all there is to it. A `.txt` is not an executable either but you can do `System.Process.Start("file.txt")` and it will work. I have updated my answer to explain. – Colin Pickard Nov 04 '10 at 13:24
  • You are 100% correct. Should have researched: "..Therefore, the file name does not need to represent an executable file. It can be of any file type for which the extension has been associated with an application installed on the system." -MSDN – Samuel Nov 04 '10 at 13:32

3 Answers3

5

If you have a setup.exe with your msi, run that instead. Otherwise, use this code:

Process p = new Process();
p.StartInfo.FileName = "msiexec";
p.StartInfo.Arguments = "/i PathToYour.msi";
p.Start();

(from here: MSI doesn't run from within C#)

The reason for needing to do it this way is that when you do System.Process.Start("file.txt") it will work since it is (sort of) calling notepad.exe %1 which will work for a text file but msiexec %1 will not work for a msi, since msiexec has a required parameter (Option).

You can test this yourself, by trying msiexec file.msi on the command line - it will give you this helpful little message:

msi without an option

Community
  • 1
  • 1
Colin Pickard
  • 45,724
  • 13
  • 98
  • 148
  • nProcess = New System.Diagnostics.Process nProcess.StartInfo.FileName = "msiexec" nProcess.StartInfo.Arguments = "/i c:\test.msi" nProcess.Start() – tambo Nov 04 '10 at 13:28
  • @umarali1 if you type `msiexec /i test.msi` into your console, does that work? If not, what is the error message? – Colin Pickard Nov 04 '10 at 13:29
  • The installation package could not be opened. Contact application vendor – tambo Nov 04 '10 at 13:55
  • that probably means there is something wrong with the msi. you say double clicking on it works? what happens if you right click on it and select install? – Colin Pickard Nov 04 '10 at 14:02
  • that produces the same error, this happens on all msi files e.g. tried a range, even msi files from microsoft website. any suggestions. – tambo Nov 04 '10 at 14:08
  • very strange. Something more fundamental wrong with the machine then I guess. I'm afraid I don't know the answer to that. – Colin Pickard Nov 04 '10 at 15:32
  • @tambo, try `msiexec /passive /package "test.msi"` – Colin Pickard Nov 08 '10 at 11:55
0

Had the same problem. The problem lies on declaring the path of the msi. You need to put double quotes around it.

Instead of

p.StartInfo.Arguments = "/i PathToYour.msi"

try

p.StartInfo.Arguments = "/i ""PathToYour.msi"""
0

To help pinpoint the problem, try running some other .exe from your code, like notepad.exe.

System.Process.Start("notepad.exe")
DOK
  • 32,337
  • 7
  • 60
  • 92