Possible Duplicate:
How to start a process from C#?
I want to start a external executable running in command line to do some task. After it is done, I want to check the errorcode it returns. How can I do it?
Possible Duplicate:
How to start a process from C#?
I want to start a external executable running in command line to do some task. After it is done, I want to check the errorcode it returns. How can I do it?
Try this:
public virtual bool Install(string InstallApp, string InstallArgs)
{
System.Diagnostics.Process installProcess = new System.Diagnostics.Process();
//settings up parameters for the install process
installProcess.StartInfo.FileName = InstallApp;
installProcess.StartInfo.Arguments = InstallArgs;
installProcess.Start();
installProcess.WaitForExit();
// Check for sucessful completion
return (installProcess.ExitCode == 0) ? true : false;
}
Process process = new Process();
process.StartInfo.FileName = "[program name here]";
process.StartInfo.Arguments = "[arguments here]";
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
process.Start();
process.WaitForExit();
int code = process.ExitCode;
You can use the Process.Start()
method.
There are both instance and static methods for launching the processing, depending on how you want to do it.
You can view MSDN documentation here. It will describe everything you need for manipulating and monitoring an external process launched from C#.
You can use the Process class' Start static method. For example, to start internet explorer minimized, and make it go to www.example.com :
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe", "www.example.com");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);
Regarding the return value, if the operation is successful, the method will return true, otherwise, a Win32Exception will be raised. You can check the NativeErrorCode member of that class to get the Win32 error code associated with that specific error.