Silent installation
Asked Answered
R

5

7

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();
Ruck answered 26/8, 2011 at 10:23 Comment(6)
please show some source code - esp. the part where you call the external EXE for installation.Dg
@ Yahia: I added the code I have used...Ruck
Have you (successfully) tried to run the "external installer" with the /quiet option directly, e.g. from a command prompt?Carollcarolle
Does the installer run without the /quiet argument? I think you should p.WaitForExit();Soldiery
@ Christian.K: Yes, I could...Ruck
@ VVS: it doesn t work with WaitForExit() also...Ruck
E
8

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
        }
    }
Eustashe answered 26/8, 2011 at 11:24 Comment(1)
I called RunInstallMSI within the override for Commit in the InstallerClass, but it says that another installation is already in progress and does not allow to install the external exe during application installation.... any reason why or any solution???Ruck
Z
3

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();
Zimmer answered 17/9, 2015 at 5:6 Comment(0)
H
0

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

Haiphong answered 12/4, 2013 at 17:53 Comment(0)
S
0

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...
}
Siliceous answered 5/3, 2021 at 19:27 Comment(0)
O
0
string filePath = @"C:\Temp\Something.msi";    
Process.Start(filePath, @"/quiet").WaitForExit();

It worked for me.

Oraorabel answered 23/6, 2021 at 2:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.