1

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?

pangular
  • 699
  • 7
  • 27
Praveen
  • 231
  • 1
  • 4
  • 15

1 Answers1

1

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

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206