如何运行在C#中静默安装 [英] How to run silent installer in C#

查看:2450
本文介绍了如何运行在C#中静默安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的C#代码:

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Process.Start("cmd.exe", "/c" + desktopPath + "\\" + "MyInstaller_7.1.51.14.exe –s –v –qn");

第一行得到我的桌面,.exe文件所在的路径。字符串 desktopPath 在第二行中使用。

The first line gets the path of my desktop where the .exe is located. The string desktopPath is used in the second line.

第二行的应该以开始在静默模式下安装程序,使程序在后台运行和安装向导不会出现在所有。运行 desktopPath +\\的字符串结果+MyInstaller_7.1.51.14.exe -s -v -qn在命令提示符下工作得很好,并且安装程序在无声模式下运行。如果你想知道的。

The second line is supposed to start the installer in silent mode, so that the process runs in the background and the installation wizard does NOT appear at all. Running the string result of desktopPath + "\\" + "MyInstaller_7.1.51.14.exe –s –v –qn" in the command prompt works just fine, and the installer runs in silent mode. In case anyone is wondering, the string result of

desktopPath +\\+MyInstaller_7.1.51.14.exe -s -v -qn

ç :\Users\ME\Desktop\MyInstaller_7.1.51.14.exe -s -v -qn

和运行此在命令提示符下运行以静默方式安装。

and running this in the command prompt runs the installation in silent mode.

Unfortunately, triggering the same command in C# code as this: 

不幸的是,引发C#代码相同的命令,因为这>的Process.Start(cmd.exe的,/ C+ desktopPath +\\+MyInstaller_7.1.51.14.exe -s -v -qn);

Process.Start("cmd.exe", "/c" + desktopPath + "\\" + "MyInstaller_7.1.51.14.exe –s –v –qn");



不以静默模式运行安装程序。相反,向导出现,对用户可见。

does not run the installer in silent mode. Instead, the wizard comes up, visible to the user.

有谁知道我怎么能修改此:

Does anyone know how I can modify this:

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Process.Start("cmd.exe", "/c" + desktopPath + "\\" + "MyInstaller_7.1.51.14.exe –s –v –qn");



,以便安装程序实际上是在静默模式运行,无需安装UI表现??

so that the installer actually runs in silent mode, without the installer UI showing??

边注:-s -v -qn是在无声模式下运行开关

推荐答案

试试这个,它为我的作品:

Try this, it works for me:

ProcessStartInfo psi = new ProcessStartInfo();
psi.Arguments = "–s –v –qn";
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.FileName = "MyInstaller_7.1.51.14.exe";
Process.Start(psi);



我不知道,如果你只要试图隐藏窗口的参数,但也许就是这样,它的一部分不会neccesary了。

I don't know if the arguments you provided tried to hide the window, but perhaps like this, part of it won't be neccesary anymore.

请注意,我用的notepad.exe为我的测试中它是成功的。也许你的安装不同的反应。

Note that I used "notepad.exe" for my tests which were successful. Perhaps your installer reacts differently.

这篇关于如何运行在C#中静默安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆