After reading this article, 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 );
}
Compares the Handle in the main window of the specified process with that in ArrayList. If yes, It is disabled.
System. Diagnostics. Process [] process = System. Diagnostics. Process. GetProcessesByName (this. listBox1.SelectedItem. ToString ());
Foreach (System. Diagnostics. Process p in process)
{
If (p. main1_whandle = (System. IntPtr) (when whandle [this. listBox2.SelectedIndex])
{
P. Kill ();
This. listBox2.Items. RemoveAt (this. listBox2.SelectedIndex );
}
}
In this way, the process with the main form can be closed, but the process without the main form does not work.
Please kindly advise