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 | $MethodDefinition = @' [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern int GetWindowText(IntPtr hWnd, string strText, int maxCount); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern int GetWindowTextLength(IntPtr hWnd); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern int GetClassName(IntPtr hWnd, string lpClassName, int nMaxCount); // Delegate to filter which windows to include. Required by EnumWindows() public delegate bool EnumWindowsProc(IntPtr hwnd, System.Collections.ArrayList lParam); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, System.Collections.ArrayList lParam); // These two functions are in C# because I can't figure out how to use the .NET API callback functionality via PowerShell public static System.Collections.ArrayList GetWindows() { System.Collections.ArrayList windowHandles = new System.Collections.ArrayList(); EnumWindowsProc callBackPtr = GetWindowHandle; EnumWindows(callBackPtr, windowHandles); return windowHandles; } private static bool GetWindowHandle(IntPtr hwnd, System.Collections.ArrayList windowHandles) { windowHandles.Add(hwnd); return true; } '@ Add-Type -MemberDefinition $MethodDefinition -Name 'ShowHideWindow' -Namespace 'User32' | Out-Null $hwnds = [User32.ShowHideWindow]::GetWindows() # Quick method to create a string of ~290 characters [String]$tempString = (0..100) $stringLength = $tempString.Length [System.Collections.ArrayList]$Windows = @() foreach ($hwnd in 66340..65552) { $ClassNameLength = [User32.ShowHideWindow]::GetClassName($hwnd, $tempString, $stringLength) $ClassName = $tempString.Substring(0,$ClassNameLength) $ClassName $WindowTextLength = [User32.ShowHideWindow]::GetWindowText($hWnd, $tempString, $stringLength) $WindowText = $tempString.Substring(0,$WindowTextLength) $WindowText } |
Obtener el nombre de las clases de las ventanas de los procesos que se están ejecutando de una ventana de un proceso pasando un rango de identificadores de ventana (PowerShell, C)
Except where otherwise noted, Jesusninoc by Jesús N. is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.