using System;
using System.ComponentModel;
using System.Diagnostics;
.....
private
void Button_Click(
object sender, EventArgs e)
{
// process
Process myProcess =
new Process();
try
{
// pathName
string pathName =
@"C:\WINDOWS\notepad.exe" ;
// myProcess.StartInfo
myProcess.StartInfo.FileName = pathName;
myProcess.Start();
clearButton.Enabled =
false ;
// waitForExit();
myProcess.WaitForExit();
msgLabel.Text =
"Process End" ;
clearButton.Enabled =
true ;
myProcess.Close();
}
catch (Win32Exception exception)
{
msgLabel.Text +=
"Err" ;
if (exception.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
msgLabel.Text +=
"(ERROR_FILE_NOT_FOUND)" ;
}
else
if (exception.NativeErrorCode == ERROR_ACCESS_DENIED) {
msgLabel.Text +=
"(ERROR_ACCESS_DENIED)" ;
}
}
}
转载于:https://blog.51cto.com/jammeswang/244970