Get system processes and end a specified process (C #)

zhaozj2021-02-16  118

See this article, close the specified IE instance: http://www.c-sharpcorner.com/code/2002/mar/captrunieinstances.asp you think about another way to make a first modification registry: hkey_local_machine // system // CurrentControlSet // Service // PerfProc // under the Performance: Disable Performance Counters value of 0 to obtain the current process system, added to the listBox: System.Diagnostics.Process [] processOnComputer = System.Diagnostics.Process.GetProcesses ( ); foreach (System.Diagnostics.Process p in processOnComputer) {this.listBox1.Items.Add (p.ProcessName);} close a specified process: System.Diagnostics.Process [] process = System.Diagnostics.Process. GetProcesSbyName (this.listbox1.selected); foreach (system.diagnostics.process p in process) {p.kill ();} But this will turn off all instances of the process, such as if you have opened multiple IEs, Will close all IE windows. Next, a particular IE instance declare an arraylist: arraylist (); get all instances of the specified process, put it in a listbox, put the Handle of the main window in ArrayList: System.Diagnostics. Process [] processOnComputer = System.Diagnostics.Process.GetProcessesByName (this.listBox1.SelectedItem.ToString ()); foreach (System.Diagnostics.Process p in processOnComputer) {this.listBox2.Items.Add (p.MainWindowTitle); / / Display the title of the main form of the main form for the title of the main form "} in listbox;

The comparison of the host window of the main window of the specified process is closed if you meet, if you meet, turn off system.diagnostics.process [] process = system.diagnostics.Process.getProcessesbyName (this.ListBox1.selectedItem.toString ()); Foreach System.Diagnostics.Process P in process) {if (p.mainwindowhandle == (system.intptr) (WindowHandle [this.listbox2.selected ") {p.kill (); this.listbox2.Items.Removeat (this. Listbox2.selectedindex;}} This can close the process with the main form, but there is no main form, please pay more attention.

转载请注明原文地址:https://www.9cbs.com/read-14205.html

New Post(0)