/*
* Programming language: Visual Studio. net c # (Beta 2)
* Author: dipolwe
* Function: Use the C # program to call the Windows Notepad program to edit
* A text file named test.txt.
*
* In the entire program, System. Diagnostics. Process. Start (Info)
* Is the main statement.
* If you only execute an external program separately, you can use the following code:
* System. Diagnostics. Process. Start (
* "External program name", "Startup parameter ");
*/
Using System;
Class test
{
Static void Main ()
{
// Declare a Program Information Class
System. Diagnostics. ProcessStartInfo Info = new System. Diagnostics. ProcessStartInfo ();
// Set the external program name
Info. FileName = "notepad.exe ";
// Set the startup sequence of the program to test.txt.
Info. Arguments = "test.txt ";
// Set the external program working directory to C:
Info. WorkingDirectory = "C :\";
// Declare a program class
System. Diagnostics. Process Proc;
Try
{
//
// Start an external program
//
Proc = System. Diagnostics. Process. Start (Info );
}
Catch (System. ComponentModel. Win32Exception e)
{
Console. WriteLine ("the specified program file cannot be found. {0} ", e );
Return;
}
// Print the start time of the external program
Console. WriteLine ("Start Time of the external program: {0}", Proc. StartTime );
// Wait 3 seconds
Proc. WaitForExit (3000 );
// Forcibly terminate an external program if it has not ended
If (Proc. HasExited = false)
{
Console. WriteLine ("the main program forcibly terminates the running of the external program! ");
Proc. Kill ();
}
Else
{
Console. WriteLine ("the external program Exits normally! ");
}
Console. WriteLine ("external program end running time: {0}", Proc. ExitTime );
Console. WriteLine ("returned value of an external program when it stops running: {0}", Proc. ExitCode );
}
}