tags:

views:

153

answers:

1

Hi all,

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.

+14  A: 

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
}
CMS
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: http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo_members.aspx
Oliver
Yes the code works!!! Thank you very much and the response also very fast.