5

Is there a solution/references on how to open or execute certain window programs in C#? For example if i want to open WinZIP or notepad application?

Example on the line of codes are more helpful. But anything are welcomed.

thank you.

1
  • 1
    Gah. How many variants "How do I execute another program in C#?" question exist on SO? Commented Aug 27, 2009 at 7:05

1 Answer 1

15

You can use the System.Diagnostics.Process.Start method.

Process.Start("notepad.exe");

It will work with files that have associated a default program:

Process.Start(@"C:\path\to\file.zip"); 

Will open the file with its default application.

And even with URLs to open the browser:

Process.Start("http://stackoverflow.com"); // open with default browser

Agree with @Oliver, ProcessStartInfo gives you a lot of more control over the process, an example:

ProcessStartInfo startInfo = new ProcessStartInfo();

startInfo.FileName = "notepad.exe";
startInfo.Arguments = "file.txt";
startInfo.WorkingDirectory = @"C:\path\to";
startInfo.WindowStyle = ProcessWindowStyle.Maximized;

Process process = Process.Start(startInfo);

// Wait 10 seconds for process to finish...
if (process.WaitForExit(10000))
{
     // Process terminated in less than 10 seconds.
}
else
{
     // Timed out
}
Sign up to request clarification or add additional context in comments.

1 Comment

To gain more control over how the process starts you should take a look into the ProcessStartInfo, which can also be used as argument for Process.Start(). Take a look here: msdn.microsoft.com/en-us/library/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.