You can use another override of the Process.Start
method that accepts a ProcessStartInfo
argument. This class has a WindowStyle
property that you can set to ProcessWindowStyle.Hidden
. This will make whatever window created by the process be hidden.
ProcessStartInfo process_start_info = new ProcessStartInfo();
process_start_info.WindowStyle = ProcessWindowStyle.Hidden;
process_start_info.FileName = @"C:\ProgramData\chocolatey\bin\choco.exe";
process_start_info.Arguments = "install googlechrome";
var process = Process.Start(process_start_info);
process.WaitForExit();
Please note that I am executing choco.exe directly instead of executing the cmd.exe. But if you are able to use cmd.exe then this should not be an issue.
Please note also that I am storing the result of invoking Process.Start
into a variable and then I am using the WaitForExit
method to wait for the process to finish. After that you can simply start a new process to install a new package using similar code. You can encapsulate this functionality into some method and use it multiple times.