Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在后台以编程方式安装软件_C# - Fatal编程技术网

C# 在后台以编程方式安装软件

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 \

我正在尝试制作一个应用程序来帮助我在其他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);
            }
错误: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