在后台以编程方式安装软件
本文关键字:安装 软件 方式 编程 后台 | 更新日期: 2023-09-27 17:54:36
我试图使一个应用程序,帮助我在其他PC上安装软件,我使用这个代码,但不幸的是没有工作:
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);
}
ERROR: T
msiexec.exe
是安装 * msi文件!
您的re-6u24-windows-i586.exe
是独立的可执行文件。
必须分配给p.StartInfo.FileName
属性!
并且p.StartInfo.Arguments
必须包含此特定安装程序的参数! /qn
是msi包的参数!
要找出问题所在,您需要获得流程的输出:
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);
}
您收到的错误代码意味着
ERROR_INSTALL_PACKAGE_INVALID(1620)这个安装包不能打开了。请与应用程序供应商联系,以验证这是一个有效的Windows安装程序包。
所以我猜这不是一个msi包。也许你需要直接调用exe,而不使用msiexec?