6

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

是否有任何理由这样做或如何使用 C# 在静默模式下安装?

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

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

5 回答 5

8

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

    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
        }
    }
于 2011-08-26T11:24:27.950 回答
1

这对我有用。

Process process = new Process();
process.StartInfo.FileName = @ "C:\PATH\Setup.exe";
process.StartInfo.Arguments = "/quiet";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.WaitForExit();
于 2015-09-17T05:06:15.853 回答
0

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

p.StartInfo.Arguments = "/Q";

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

于 2013-04-12T17:53:11.590 回答
0
string filePath = @"C:\Temp\Something.msi";    
Process.Start(filePath, @"/quiet").WaitForExit();

它对我有用。

于 2021-06-23T02:17:38.537 回答
0

这是我为所有用户静默安装应用程序的逻辑:

public void Install(string filePath)
{
    try
    {
        Process process = new Process();
        {
            process.StartInfo.FileName = filePath;
            process.StartInfo.Arguments = " /qb ALLUSERS=1";
            process.EnableRaisingEvents = true;
            process.Exited += process_Exited;
            process.Start();
            process.WaitForExit();
        }
    }
    catch (InvalidOperationException iex)
    {
        Interaction.MsgBox(iex.Message, MsgBoxStyle.OkOnly, MethodBase.GetCurrentMethod().Name);
    }
    catch (Exception ex)
    {
        Interaction.MsgBox(ex.Message, MsgBoxStyle.OkOnly, MethodBase.GetCurrentMethod().Name);
    }
}

private void process_Exited(object sender, EventArgs e)
{
    var myProcess = (Process)sender;
    if (myProcess.ExitCode == 0)
        // do yours here...
}
于 2021-03-05T19:27:53.533 回答