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.
In Windows to execute a program, double-click the executable file or double-click the shortcut icon pointing to the executable file. If you have a hard time double-clicking an icon, click the icon once to highlight it and then press Enter on the keyboard.
To compile a simple C program, we use the Linux command-line tool, the terminal. To open the terminal, you can use the Ubuntu Dash or the key combination Ctrl+Alt+T.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With