MSI不在C#内运行

Cwi*_*ing 7 c# windows-installer

我试图使用Proces.Start方法从C#运行MSI文件.MSI文件很好,因为我可以正常运行,但是当我尝试在某些C#代码中运行MSI文件时,我收到以下错误.

"无法打开此安装包.验证包是否存在,以及您是否可以访问它,或联系应用程序供应商以验证这是否是有效的Windows安装程序包"

下面是我用来运行MSI文件的代码......

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

p.WaitForExit();   
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?


好的,我现在明白了.我刚刚更改它以运行使用MSI文件生成的setup.exe文件,而不是运行MSI文件...

Ben*_*zun 15

msi文件无法自行运行.如果双击它们,Windows将启动

msiexec /i PathToYour.msi

你有没有明确地这样做?

示例:(由@Webleeuw提供)

Process p = new Process();
p.StartInfo.FileName = "msiexec";
p.StartInfo.Arguments = "/i PathToYour.msi";
p.Start();
Run Code Online (Sandbox Code Playgroud)


Web*_*euw 9

除了质疑海报对本杰明回答的评论:

Process p = new Process();
p.StartInfo.FileName = "msiexec";
p.StartInfo.Arguments = "/i PathToYour.msi";
p.Start();
Run Code Online (Sandbox Code Playgroud)

  • 对我不起作用.由于某种原因,它显示了Windows安装程序框的说明. (2认同)

Dir*_*mar 8

也可以直接使用关联的应用程序执行.msi文件.设置UseShellExecutetrue:

Process.Start(new ProcessStartInfo() 
{ 
    FileName = @"c:\somepath\mySetup.msi", 
    UseShellExecute = true 
});
Run Code Online (Sandbox Code Playgroud)