Skip to content

Instantly share code, notes, and snippets.

@lazywinadmin
Created February 1, 2016 15:31
Show Gist options
  • Save lazywinadmin/7906af194ce5e7dd1556 to your computer and use it in GitHub Desktop.
Save lazywinadmin/7906af194ce5e7dd1556 to your computer and use it in GitHub Desktop.
Get UI Information for Processes
<# 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