windows 静默安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7203300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:56:47  来源:igfitidea点击:

Silent installation

c#windowssilent-installer

提问by Dulini Atapattu

I am writing a InstallerClassusing C#as a custom action for my installer, and I can successfully run an external exe (installation) using the InstallerClass, but when I try to use /quietin the InstallerClass, it does not install the exe. But I can successfully install this in silent mode using /quietin the command prompt.

我正在为我的安装程序编写一个InstallerClassusingC#作为自定义操作,我可以使用 成功运行外部 exe(安装)InstallerClass,但是当我尝试在 中使用/quietInstallerClass,它不会安装 exe。但是我可以/quiet在命令提示符下以静默模式成功安装它。

Is there any reason for this or otherwise how to install in silent mode using C#?

是否有任何原因或其他方式如何使用 C# 在静默模式下安装?

Following is the code I use within the Commit method (overriden):

以下是我在 Commit 方法中使用的代码(覆盖):

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = pathExternalInstaller;
p.StartInfo.Arguments = "/quiet";
p.Start();

回答by Mark Kram

Here is what I use to do a quiet Install and Uninstall:

这是我用来进行安静安装和卸载的方法:

    public static bool RunInstallMSI(string sMSIPath)
    {
        try
        {
            Console.WriteLine("Starting to install application");
            Process process = new Process();
            process.StartInfo.FileName = "msiexec.exe";
            process.StartInfo.Arguments = string.Format(" /qb /i \"{0}\" ALLUSERS=1", sMSIPath);      
            process.Start();
            process.WaitForExit();
            Console.WriteLine("Application installed successfully!");
            return true; //Return True if process ended successfully
        }
        catch
        {
            Console.WriteLine("There was a problem installing the application!");
            return false;  //Return False if process ended unsuccessfully
        }
    }

    public static bool RunUninstallMSI(string guid)
    {
        try
        {
            Console.WriteLine("Starting to uninstall application");
            ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe", string.Format("/c start /MIN /wait msiexec.exe /x {0} /quiet", guid));
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            Process process = Process.Start(startInfo);
            process.WaitForExit();
            Console.WriteLine("Application uninstalled successfully!");
            return true; //Return True if process ended successfully
        }
        catch
        {
            Console.WriteLine("There was a problem uninstalling the application!");
            return false; //Return False if process ended unsuccessfully
        }
    }

回答by Pushpak Gupta

This works for me.

这对我有用。

Process process = new Process();
process.StartInfo.FileName = @ "C:\PATH\Setup.exe";
process.StartInfo.Arguments = "/quiet";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.WaitForExit();

回答by ijb109

Have you tried using the /Qor /QBparameter that is listed in the Installation parameters? It might look something like this:

您是否尝试使用安装参数中列出的/Qor/QB参数?它可能看起来像这样:

p.StartInfo.Arguments = "/Q";

p.StartInfo.Arguments = "/Q";

I got that out of this document: http://msdn.microsoft.com/en-us/library/ms144259(v=sql.100).aspx

我从这个文档中得到了这个:http: //msdn.microsoft.com/en-us/library/ms144259(v=sql.100).aspx