Original: C # forces the current program process to close (completely kill without leaving traces)
C # Forces the current program process to close (completely kill without leaving traces)
C # code
- // <summary>
- /// Run DOS command
- ///DOS Shutdown process command (ntsd-c q-p PID) PID for process ID
- // </summary>
- /// <param name= "command" ></param>
- // <returns></returns>
- public static string Runcmd (String c15> command)
- {
- //Example a process to activate a stand-alone process
- System.Diagnostics.Process p = New System.Diagnostics.Process ();
- //process has a startinfo, which is processstartinfo, including some of its own nature and methods, and below we have used his several:
- p.StartInfo.FileName = "cmd.exe" ; //Set Program name
- p.startinfo.arguments = "/C" + command; //Set program to perform the parameters
- P.startinfo.useshellexecute = false ; //Close the use of the shell
- p.startinfo.redirectstandardinput = true ; //redirect standard input
- p.startinfo.redirectstandardoutput = true ; //redirect standard output
- P.startinfo.redirectstandarderror = true ; //redirect wrong output
- P.startinfo.createnowindow = true ; //Setup does not display the window
- P.start (); //activation
- //p.standardinput.writeline (command); You can also enter commands to execute in this way
- //p.standardinput.writeline ("exit"); But remember to add the exit or the next line of code will be
- return p.standardoutput.readtoend (); //from the output stream to get the command to perform the results
- }
<summary>///Run DOS command//DOS shutdown process command (ntsd-c q-p PID) PID for process ID//</summary> <param name= "command" ></param>///<returns></returns> public Stati C string Runcmd (String command) {//An instance of a process, activating a stand-alone process System.Diagnostics.Process p = new System.Diagnostics.Process (); The process has a startinfo, which is processstartinfo, including some of its own nature and methods, and the following we have used his several: p.StartInfo.FileName = "cmd.exe"; Set Program Name p.startinfo.arguments = "/C" + command; Set Program to execute parameters P.startinfo.useshellexecute = false; Close the shell using P.startinfo.redirectstandardinput = true; REDIRECT Standard input p.startinfo.redirectstandardoutput = true; REDIRECT Standard output P.startinfo.redirectstandarderror = true; redirect wrong output P.startinfo.createnowindow = true; Setup does not display the window P.start (); Activate P.standardinput.writeline (command); You can also enter the command//p.standardinput.writeline ("Exit") to execute in this way; But remember to add the exit or the next line of the program will return to P.standardoutput.readtoend (); Get command from output stream to perform results}
In Program.cs Add the following
C # code
- Static class program
- {
- // <summary>
- /// The main entry point of the application.
- // </summary>
- [STAThread]
- static void Main ()
- {
- Application.enablevisualstyles ();
- Application.setcompatibletextrenderingdefault (false);
- Application.Run (new mainform ());
- //Force shutdown process
- string exename = System.Diagnostics.Process.GetCurrentProcess (). Mainmodule.filename;
- string[] Exearray = Exename.split (' \ \ ');
- functionclass.runcmd ("Taskkill/im" + exearray[exearray.length-1] + "/ F ");
- }
- }
C # Forces the current program process to close (completely kill without leaving traces)