I have a c# app (app.exe), which I want to run from a command line window and then to CLOSE the command line window after the app started.
I tried to search for "cmd" in the processes list and to close it (cmdProcess.CloseMainWindow()) but in this case, if I run app.exe by double-click only, and there is another cmd opened separately, it will be closed- and I don't want that. How can I know which cmd instance runs my app?
thanks
In Windows Command prompt it's "&" to attach commands in one line. So it'll be:
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/k " + Command + " & exit";
But if you read the "cmd /?", you'll see that the purpose of "/k" argument is to keep the window. So if it's not what you want, just use the "/c" argument instead.
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/c " + Command;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With