C# 在后台以编程方式安装软件
我正在尝试制作一个应用程序来帮助我在其他PC上安装软件,我正在使用此代码,但不幸的是无法正常工作:C# 在后台以编程方式安装软件,c#,C#,我正在尝试制作一个应用程序来帮助我在其他PC上安装软件,我正在使用此代码,但不幸的是无法正常工作: string filename = "Java\\jre-6u24-windows-i586.exe"; Process p = new Process(); p.StartInfo.FileName = "msiexec.exe"; p.StartInfo.Arguments = "/i \
string filename = "Java\\jre-6u24-windows-i586.exe";
Process p = new Process();
p.StartInfo.FileName = "msiexec.exe";
p.StartInfo.Arguments = "/i \"" + filename + "\" /qn";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
if (p.ExitCode != 0)
{
MessageBox.Show("ERROR: " + output);
}
错误:T
要找出问题所在,您需要获得流程的输出:
string filename ="Java\\jre-6u24-windows-i586.exe";
Process p = new Process();
p.StartInfo.FileName = "msiexec.exe";
p.StartInfo.Arguments = "/i \""+filename+"\" /qn";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
if(p.ExitCode != 0)
{
MessageBox.Show("ERROR: " + output);
}
您收到的错误代码意味着
错误\u安装\u程序包\u无效(1620)无法安装此安装程序包
开的。请与应用程序供应商联系,以验证这是一个有效的Windows应用程序
安装程序包
所以我猜这不是msi软件包。也许您需要直接调用exe,而不使用msiexec?
msiexec.exe
是为了安装*.msi文件您的
re-6u24-windows-i586.exe是一个可独立执行的。
必须将其分配给p.StartInfo.FileName
属性
并且p.StartInfo.Arguments
必须包含此特定安装程序的参数/qn
是MSI包的参数 “不幸没有工作”-有例外吗?什么叫“不工作”?您是否检查了进程的输出是否有错误消息?胡乱猜测:将文件名+“\”/qn”
部分更改为在文件名和/qn
之间包含空格。是否可以输出ExitCode属性?@nvoigt我得到的结果:1620