Start a command line including arguments from C#

13,402

Solution 1

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";

Solution 2

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

Share:
13,402
Stefan Koell
Author by

Stefan Koell

Being a freelance consultant I mainly do infrastructure projects specialized in monitoring, systems management, deployment, automation and software development.

Updated on June 04, 2022

Comments

  • Stefan Koell
    Stefan Koell almost 2 years

    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)?

  • Adam Lear
    Adam Lear about 13 years
    You'll probably need the /c switch to tell cmd.exe to execute app.exe.
  • Stefan Koell
    Stefan Koell about 13 years
    I also thought about this solution but I don't like that the command window appears.
  • Stefan Koell
    Stefan Koell about 13 years
    I'm aware of this property but this still requires me to pass in the command and the arguments separately.