Obtenido el código de http://powershell-knowhow.de/powershell/?p=321
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
<# .Synopsis Enumerieren der vorhandenen Fenster #> $TypeDef = @" using System; using System.Text; using System.Collections.Generic; using System.Runtime.InteropServices; namespace Api { public class WinStruct { public string WinTitle {get; set; } public int WinHwnd { get; set; } } public class ApiDef { private delegate bool CallBackPtr(int hwnd, int lParam); private static CallBackPtr callBackPtr = Callback; private static List<WinStruct> _WinStructList = new List<WinStruct>(); [DllImport("User32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool EnumWindows(CallBackPtr lpEnumFunc, IntPtr lParam); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); private static bool Callback(int hWnd, int lparam) { StringBuilder sb = new StringBuilder(256); int res = GetWindowText((IntPtr)hWnd, sb, 256); _WinStructList.Add(new WinStruct { WinHwnd = hWnd, WinTitle = sb.ToString() }); return true; } public static List<WinStruct> GetWindows() { _WinStructList = new List<WinStruct>(); EnumWindows(callBackPtr, IntPtr.Zero); return _WinStructList; } } } "@ Add-Type -TypeDefinition $TypeDef -Language CSharpVersion3 [Api.Apidef]::GetWindows() | Where-Object { $_.WinTitle -ne "" } | Sort-Object -Property WinTitle | Select-Object WinTitle,@{Name="Handle"; Expression={"{0:X0}" -f $_.WinHwnd}} |