Created
February 1, 2016 15:31
-
-
Save lazywinadmin/7906af194ce5e7dd1556 to your computer and use it in GitHub Desktop.
Get UI Information for Processes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# PowerShell.Com | |
PowerShell can use UIAutomation calls to find out useful UI information about any process. | |
You can find out whether a process accepts keyboard input, whether it is currently visible | |
(and what its window dimensions are), and whether it is a native Win32 application | |
or uses WPF--among other things. | |
Here is an example that examines two processes: the PowerShell window, and a minimized Notepad: | |
#> | |
#requires -Version 2 | |
function Get-ProcessInfoUI($Process) | |
{ | |
foreach ($proc in $Process) | |
{ | |
Add-Type -AssemblyName UIAutomationClient | |
[System.Windows.Automation.AutomationElement]::FromHandle($proc.MainWindowHandle).Current | | |
Select-Object -Property Name, HasKeyboardFocus, IsOffscreen, BoundingRectangle, NativeWindowHandle, ProcessId, Orientation, FrameworkId | |
} | |
} | |
# get current PowerShell process: | |
$ise = Get-Process -Id $pid | |
# start new Notepad and wait until loaded: | |
$notepad = Start-Process notepad -WindowStyle Minimized -PassThru | |
$null = $notepad.WaitForInputIdle() | |
# get UI information for these processes | |
Get-ProcessInfoUI $ise, $notepad | Out-GridView -Title 'UI Information' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment