To go to the post of Philip Schmid, I slightly weighed the demo version:
Run it as a console application. You need to add links to UIAutomationClient and UIAutomationTypes .
One of the possible improvements that you (or I, if you wish) can make is to hide the window initially, only showing it after the correct tab has been selected. I'm not sure if this will work, but I'm not sure if AutomationElement.FromHandle can find a hidden window.
Edit: At least on my computer (Windows 7, 32 bit, .Net framework 4.0) the following code initially creates a hidden task manager and shows it after the correct tab has been selected. I do not show the window after selecting the performance tab, so perhaps one of the automation lines does this as a side effect.
using System; using System.Diagnostics; using System.Windows.Automation; namespace ConsoleApplication2 { class Program { static void Main(string[] args) {
Why am I destroying previous instances of the task manager? When the instance is already open, the secondary instances open but close immediately. My code does not check this, so the code that finds the window handle will be frozen.
source share