How do I start a process from C#?


How do I start a process, such as launching a URL when the user clicks a button?

9/7/2016 9:03:09 AM

As suggested by Matt Hamilton, the quick approach where you have limited control over the process, is to use the static Start method on the System.Diagnostics.Process class...

using System.Diagnostics;

The alternative is to use an instance of the Process class. This allows much more control over the process including scheduling, the type of the window it will run in and, most usefully for me, the ability to wait for the process to finish.

using System.Diagnostics;
Process process = new Process();
// Configure the process using the StartInfo properties.
process.StartInfo.FileName = "process.exe";
process.StartInfo.Arguments = "-n";
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
process.WaitForExit();// Waits here for the process to exit.

This method allows far more control than I've mentioned.

7/1/2014 5:57:12 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow