System.Process.Start - 运行msi问题

时间:2010-11-04 12:38:09

标签: vb.net

当我尝试在vb应用程序中使用System.Process.Start(“test.msi”)运行msi时,我收到以下错误。

无法打开安装包。联系应用程序供应商......

双击时,Msi文件工作正常,尝试使用文本文件和exe文件的System.Process.Start,它们工作正常,只有msi才有问题

的文件。运行远景。也试过xp但没有运气

由于

3 个答案:

答案 0 :(得分:5)

如果你有一个带有msi的setup.exe,那就改用它。否则,请使用以下代码:

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

(从这里:MSI doesn't run from within C#

需要这样做的原因是,当你执行System.Process.Start("file.txt")时,它会起作用,因为它(某种程度上)调用notepad.exe %1,它将适用于文本文件但是{{1}因为msiexec有一个必需的参数(选项),所以不适用于msi。

你可以自己测试一下,在命令行上尝试msiexec file.msi - 它会给你这个有用的小消息:

msi without an option

答案 1 :(得分:0)

为帮助查明问题,请尝试从代码中运行其他一些.exe文件,例如notepad.exe。

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

答案 2 :(得分:0)

有同样的问题。问题在于声明msi的路径。你需要在它周围加上双引号。

而不是

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

p.StartInfo.Arguments = "/i ""PathToYour.msi"""
相关问题