0

I am working on C# console application. It has only single requirement. It should silently install .exe setup files. These setup file are generated from InstallShield or other product. I do not generate any setup file. I tried to install Notepad++ using this code as well but it is not wokring.

To be more specific and to avoid duplicate mark to this question, I already referred many links regarding same. Some of them are

  1. http://www.c-sharpcorner.com/article/silent-installation-of-applications-using-c-sharp/
  2. C# code to run my installer.exe file in silent mode, in the background,
  3. How to run silent installer in C#

Code I tried:

OPTION-1

ProcessStartInfo psi = new ProcessStartInfo();
psi.Arguments = "/s /v /qn /min";
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.FileName = newRenamedFile;
psi.UseShellExecute = false;
Process.Start(psi);

OPTION-2

executableFilePath is path to .exe setup file.

public static void DeployApplications(string executableFilePath)
{
    PowerShell powerShell = null;
    Console.WriteLine(" ");
    Console.WriteLine("Deploying application...");

    try
    {
        using (powerShell = PowerShell.Create())
        {
            powerShell.AddScript("$setup=Start-Process '" + executableFilePath + "' -ArgumentList '/s /v /qn /min' -Wait -PassThru");

            Collection<PSObject> PSOutput = powerShell.Invoke();
            foreach (PSObject outputItem in PSOutput)
            {

                if (outputItem != null)
                {

                    Console.WriteLine(outputItem.BaseObject.GetType().FullName);
                    Console.WriteLine(outputItem.BaseObject.ToString() + "\n");
                }
            }

            if (powerShell.Streams.Error.Count > 0)
            {
                string temp = powerShell.Streams.Error.First().ToString();
                Console.WriteLine("Error: {0}", temp);

            }
            else
                Console.WriteLine("Installation has completed successfully.");

        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error occured: {0}", ex.InnerException);
    }
    finally
    {
        if (powerShell != null)
            powerShell.Dispose();
    }

}

Both OPTION-1 and OPTION-2 open setup wizard UI. There is no installtion process starts and no application gets installed on computer. There is no error while executing this code.

QUESTIONS

  1. Am I missing anything in OPTION-1/2?
  2. What is wrong with the code above?
  3. Do I need to make any specialize InstallShield Wizard to skip UI from this console application?
  4. Why is it not working even with third party applications (e.g. notepad++) ?
  5. How to avoid administration permission UI as well?

OUTPUT I WANT

Console application must install .exe files silently. Setup wizard UI must be skipped. It is fine if console window appears. I do not want any UI to be appear other than console window.

Gaurang Dave
  • 3,956
  • 2
  • 15
  • 34
  • Silent Install commands vary depending on the program itself and the installer they have used. Using `/qn` will work for _most_ (but not all!!) MSI installers, as as MS set a standard. Unlike an MSI, EXE installers do not have a _single_ silent install command/param. The silent install command can vary (wildly) between different installers. There's no easy way around this and you will have to find the specific silent install command for each individual installer and deal with them on a case-by-case basis. – henrycarteruk Feb 27 '18 at 09:37
  • Two examples of silent install commands showing different params: [`Firefox Installer.exe -ms`](https://wiki.mozilla.org/Installer:Command_Line_Arguments) and [`7z1801.exe /S`](http://www.7-zip.org/faq.html) – henrycarteruk Feb 27 '18 at 09:47

1 Answers1

0

Finally , I found solution and work around for my requirement.

Need to add app.manifest file to the WPF application with the following option. App must open with the Administrator rights.

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Change in script for silent installtion.

    private void deployApplications(string executableFilePath)
    {
        PowerShell powerShell = null;
        Console.WriteLine(" ");
        Console.WriteLine("Deploying application...");
        try
        {
            using (powerShell = PowerShell.Create())
            {
                powerShell.AddScript(executableFilePath + " /S /v/qn");

                Collection<PSObject> PSOutput = powerShell.Invoke();
                foreach (PSObject outputItem in PSOutput)
                {

                    if (outputItem != null)
                    {
                        Console.WriteLine(outputItem.BaseObject.GetType().FullName);
                        Console.WriteLine(outputItem.BaseObject.ToString() + "\n");
                    }
                }

                if (powerShell.Streams.Error.Count > 0)
                {
                    string temp = powerShell.Streams.Error.First().ToString();
                    Console.WriteLine("Error: {0}", temp);

                }
                else
                    Console.WriteLine("Installation has completed successfully.");

            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error occured: {0}", ex.InnerException);
            //throw;
        }
        finally
        {
            if (powerShell != null)
                powerShell.Dispose();
        }

    }
Gaurang Dave
  • 3,956
  • 2
  • 15
  • 34