Exercise: WinForm process (Create, logout)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.