tags:

views:

4156

answers:

5

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

+11  A: 

You can use the System.Diagnostics.Process.Start method to start a project. You can even pass a URL as a string and it'll kick off the default browser.

Matt Hamilton
A: 

Use the Process class. The MSDN documentation has an example how to use it.

Franci Penov
+1  A: 

There is another question with answers that could be given here too:

How does one load a URL from a .NET client application

Mudu
+1  A: 

Just as Matt says, use Process.Start.

You can pass a Url, or a document. They will be started by the registered application.

Example:

Process.Start("Test.Txt"):

Will start Notepad.exe with Text.Txt loaded.

GvS
+13  A: 

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

Process.Start("process.exe"):

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.

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.Start();
process.WaitForExit();// Waits here for the process to ecit.

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

Andy McCluggage