c# - 静默安装

标签 c# windows silent-installer

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

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

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

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

最佳答案

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

    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
        }
    }

关于c# - 静默安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7203300/

相关文章:

installation - 如何以静默方式安装Visual Studio Code(安装结束时不自动打开)?

c# - LINQ to SQL DataContext 不更新 ConnectionString

c# - 发送大量消息时出现 SocketException(代码 10048)

c# - 使用互操作从 COM 事件处理程序发出错误通知

windows - x64 native 工具命令提示符和 x64 交叉工具命令提示符有什么区别?

c++ - 摆脱 "warning C4267 possible loss of data"的最佳策略是什么?

C#如何定义api key 等全局常量并防止上传到Github

c - 为什么这个 MSVC API 是这样定义的?

uwp - 如何静默安装 UWP appx?

linux - 如何在 Linux 上静默安装 IBM BPM 8.5.6