Obtain the system process and end a specified process.

Source: Internet
Author: User

See this articleArticleTo disable the specified ie instance:
Http://www.c-sharpcorner.com/Code/2002/Mar/CaptRunIEInstances.asp

I thought of another way to do this.

Modify the Registry first:
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ service \ perfproc \ Performance
The value of disable performance counters is changed to 0.

Get the current process of the system and add it to ListBox:
System. Diagnostics. Process [] processoncomputer = system. Diagnostics. process. getprocesses ();
Foreach (system. Diagnostics. Process P in processoncomputer)
{
This. listbox1.items. Add (P. processname );
}

Shut down a specified process:
System. Diagnostics. Process [] process = system. Diagnostics. process. getprocessesbyname (this. listbox1.selecteditem. tostring ());

Foreach (system. Diagnostics. Process P in process)
{
P. Kill ();
}

However, this will close all instances of the process. For example, if you open multiple ie instances, all IE Windows will be closed.

The following code disables a specific ie instance:
Declare An arraylist first:
Arraylist tables whandle = new arraylist ();

Get all the instances of the specified process, put them in a ListBox, and put the handle of the main window into 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 in ListBox
Define whandle. Add (P. main1_whandle );
}

compare the handle in the main window of the specified process with that in arraylist. If yes, disable
system. diagnostics. process [] process = system. diagnostics. process. getprocessesbyname (this. listbox1.selecteditem. tostring ();
foreach (system. diagnostics. process P in process)
{< br> If (P. main1_whandle = (system. intptr) (when whandle [this. listbox2.selectedindex])
{< br> P. kill ();
This. listbox2.items. removeat (this. listbox2.selectedindex);
}< BR >}< br>
in this way, the process with the main form can be closed, however, it does not work if there is no main form.
Please advise me more

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.