Praveen
Praveen

Reputation: 261

Open cmd.exe and then run my current console application

Here's something that I want to achieve:

  1. Lets say I'm preparing abc.exe (console application).
  2. I want to invoke cmd.exe and then launch abc.exe through cmd. And I won't be keeping cmd.exe in my projects folder. I'll be using it from system32 folder from user's machine.

Is it possible?

Upvotes: 1

Views: 402

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 175085

As mentioned in comments, you can use Process.Start(pathToExe) to launch a new process.

You can start your program in a new cmd with cmd /C start "Title" "C:\path\to\app.exe":

string cmdPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe");
string exePath = System.Reflection.Assembly.GetEntryAssembly().Location;
ProcessStartInfo newCmd = new ProcessStartInfo(cmdPath);
newCmd.Arguments = String.Format(@"/C start ""{0}"" ""{1}""", "WindowTitle", exePath);
Process.Start(newCmd);

You probably want some sort of conditional around that in order to not fork bomb yourself

Upvotes: 1

Related Questions