开发者

System.Process.Start - running msi problem

开发者 https://www.devze.com 2023-01-23 06:29 出处:网络
When i try to run a msi using System.Process.Start(\"test.msi\") in a vb app i get the following error.

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 fil开发者_运维百科es and they work fine, problem only with msi

files. Running vista. Also tried xp but no luck

Thanks


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:

System.Process.Start - running msi problem


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

System.Process.Start("notepad.exe")


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

精彩评论

暂无评论...
验证码 换一张
取 消