2

I need to start a complete command line like "app.exe /arg1:1 /arg2:true" from my C# app.

Process.Start and ProcessStartInfo needs to have the filename and arguments property set. Is there a way to mimic a true shell-like execute (like the one when you press WIN+R)?

3
  • 2
    What deficiencies are you finding with using Process.Start?
    – Oded
    Jan 26, 2011 at 16:35
  • 1
    How about a batch file starting the process and using Process.Start to start the batch file? Jan 26, 2011 at 16:36
  • The command line is coming from a configuration file and is provided as a whole. I just want to mimic the WIN+R functionality. I think even VBScript has a way to do what I need... Jan 27, 2011 at 10:23

3 Answers 3

4

Yes, you can launch cmd.exe with the full command-line you want to send as the arguments.

info.FileName = "cmd.exe";
info.Arguments = "app.exe /arg1:1 /arg2:true";
2
  • 1
    You'll probably need the /c switch to tell cmd.exe to execute app.exe.
    – Adam Lear
    Jan 26, 2011 at 16:39
  • I also thought about this solution but I don't like that the command window appears. Jan 27, 2011 at 8:09
3

ProcessStartInfo.UseShellExecute makes Process.Start behave exactly like the Shell: http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx

1
  • I'm aware of this property but this still requires me to pass in the command and the arguments separately. Jan 27, 2011 at 8:22
0

I've found the solution I've been looking for: Executing another program from C#, do I need to parse the "command line" from registry myself?

Thanks again for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.