静默安装 [英] Silent installation

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

问题描述

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

I am writing a InstallerClass using 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 /quiet in the InstallerClass, it does not install the exe. But I can successfully install this in silent mode using /quiet in the command prompt.

是否有任何原因,或者是否有其他原因使用C#以静默方式安装?

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

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

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

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

推荐答案

以下是我用来安静安装和卸载的方法:

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

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

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