静默安装

发布于 2024-12-01 16:22:41 字数 495 浏览 0 评论 0原文

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

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

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

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

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.

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

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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

前事休说 2024-12-08 16:22:41

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

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

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
        }
    }
┈┾☆殇 2024-12-08 16:22:41

这对我有用。

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

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();
一百个冬季 2024-12-08 16:22:41

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

p.StartInfo.Arguments = "/Q";

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

Have you tried using the /Q or /QB parameter that is listed in the Installation parameters? It might look something like this:

p.StartInfo.Arguments = "/Q";

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

没有心的人 2024-12-08 16:22:41

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

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

Here is my logic to silent install an app for all users:

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...
}
别理我 2024-12-08 16:22:41
string filePath = @"C:\Temp\Something.msi";    
Process.Start(filePath, @"/quiet").WaitForExit();

这对我有用。

string filePath = @"C:\Temp\Something.msi";    
Process.Start(filePath, @"/quiet").WaitForExit();

It worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文