$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 = @() $ClassNameLength = [User32.ShowHideWindow]::GetClassName([uint32]"0x0001043E", $tempString, $stringLength) $ClassName = $tempString.Substring(0,$ClassNameLength) $ClassName
Obtener el nombre de una clase de una ventana de un proceso pasando el identificador de ventana en hexadecimal desde PowerShell (PowerShell, C, Automatización)
Except where otherwise noted, Jesusninoc by Jesús N. is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.