I try to launch the command prompt hidden when querying the wmic qfe list that contains my installed KB articles.
I launch the command “wmic qfe list full” from inside my command prompt and this gets me the list.
When I do this from inside my C# app, in order to let my process execution from cmd.Exe stop after the command has completed, i use the /c switch as an argument. However, since I added this switch, I can no longer have my cmd.exe launching hidden.
It pops up and executes the code and as it should do, it closes itself after execution of the command and it pipes the information to my app.
But I cannot hide it. Any advise on hiding it with the /c switch in the arguments or having it stop after the command line has been executed without the /c switch in it.
Here is my code:
private void btn_Click(object sender, EventArgs e)
{
string fileName = @"cmd.exe";
Process p = new Process();
ProcessStartInfo ps = new ProcessStartInfo();
ps.Arguments = " /c wmic qfe list full";
ps.FileName = fileName;
ps.UseShellExecute = false;
ps.WindowStyle = ProcessWindowStyle.Hidden;
ps.RedirectStandardInput = true;
ps.RedirectStandardOutput = true;
ps.RedirectStandardError = true;
p.StartInfo = ps;
p.Start();
StreamReader srrOutput = p.StandardOutput;
this.textBox1.Text = srrOutput.ReadToEnd();
}
Found it, apparently adding the /C switch also requires me to add:
ps.CreateNoWindow = true;
Now it works just fine, Should’ve googled somewhat longer..
I had the same issue as well when trying to use /c in cmd.
You have to use:
Without the /c command, the
Same issue with the /k switch.
Regards