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
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
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.
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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.