I am currently invoking the windows task manager using a click event in WPF. The event simply executes ‘Process.Start(“taskmgr”).
My question is, is there a way to choose which tab inside task manager is selected when the process starts / is displayed? I am looking to have the ‘performance’ tab selected automatically whenever the click event is raised.
Thanks for the help.
To expand on Philipp Schmid’s post, I’ve whipped up a little demo:
Run it as a console application. You need to add references to
UIAutomationClientandUIAutomationTypes.One possible improvement you (or I, if you desire) can make is to hide the window initially, only showing it after the correct tab has been selected. I’m not sure if that would work, however, as I’m not sure thatAutomationElement.FromHandlewould be able to 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 don’t explicitly show the window after selecting the performance tab, so probably one of the automation lines does as a side-effect.
Why do I destroy previous instances of Task Manager? When an instance is already open, secondary instances will open but immediately close. My code doesn’t check for this, so the code that finds the window handle will freeze.