32 lines
1.3 KiB
PowerShell
32 lines
1.3 KiB
PowerShell
|
|
Add-Type -TypeDefinition @'
|
||
|
|
using System;
|
||
|
|
using System.Text;
|
||
|
|
using System.Runtime.InteropServices;
|
||
|
|
public class WinEnum {
|
||
|
|
[DllImport("user32.dll")] static extern bool EnumWindows(EnumProc cb, IntPtr l);
|
||
|
|
[DllImport("user32.dll")] static extern int GetWindowText(IntPtr h, StringBuilder s, int n);
|
||
|
|
[DllImport("user32.dll")] static extern int GetWindowTextLength(IntPtr h);
|
||
|
|
[DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
|
||
|
|
[DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr h);
|
||
|
|
public delegate bool EnumProc(IntPtr h, IntPtr l);
|
||
|
|
public static void Dump(uint targetPid) {
|
||
|
|
EnumWindows((h, l) => {
|
||
|
|
uint pid; GetWindowThreadProcessId(h, out pid);
|
||
|
|
if (pid == targetPid && IsWindowVisible(h)) {
|
||
|
|
int len = GetWindowTextLength(h);
|
||
|
|
var sb = new StringBuilder(len + 1);
|
||
|
|
GetWindowText(h, sb, sb.Capacity);
|
||
|
|
Console.WriteLine(" hwnd={0} title='{1}'", h, sb.ToString());
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}, IntPtr.Zero);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
'@
|
||
|
|
$procs = Get-Process TcXaeShell -ErrorAction SilentlyContinue
|
||
|
|
if (-not $procs) { Write-Host "no TcXaeShell running"; exit 0 }
|
||
|
|
foreach ($p in $procs) {
|
||
|
|
Write-Host "PID $($p.Id):"
|
||
|
|
[WinEnum]::Dump([uint32]$p.Id)
|
||
|
|
}
|