usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.Diagnostics;namespaceProcess { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } //To Create a process: Private voidButton1_Click (Objectsender, EventArgs e) { //set the type of open fileOpenfiledialog1.filter ="Application |*.exe"; //displays a dialog box and determines if the user has selected a file if(Openfiledialog1.showdialog () = =DialogResult.OK) {//Gets the file path selected by the user stringPath =Openfiledialog1.filename; //Create a Process objectProcess p =NewProcess (); //To Create a startup information objectProcessStartInfo psi =NewProcessStartInfo (path); //Set process startup informationP.startinfo =psi; //START ProcessP.start (); //End Process//P.kill (); } }
//Logoff process: Private voidButton3_Click (Objectsender, EventArgs e) { //1. Open the program//get the path to the program file//string path = Application.startuppath; (absolute path to program: No last name and file type) stringPath =System.Reflection.Assembly.GetExecutingAssembly (). Manifestmodule.fullyqualifiedname; //Create a Process objectProcess p =NewProcess (); //To Create a startup information objectProcessStartInfo psi =NewProcessStartInfo (path); //Set Startup informationP.startinfo =psi; //START ProcessP.start (); //2. Close the program This. Close (); } }}
Exercise: WinForm process (Create, logout)