# 枚举 MuMu 相关进程的所有顶层窗口(全部逻辑在 C# 内完成) Add-Type -TypeDefinition @" using System; using System.Text; using System.Collections.Generic; using System.Runtime.InteropServices; public class WinEnum2 { public delegate bool EnumProc(IntPtr hWnd, IntPtr lParam); [DllImport("user32.dll")] public static extern bool EnumWindows(EnumProc cb, IntPtr lParam); [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint pid); [DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder sb, int max); [DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetClassName(IntPtr hWnd, StringBuilder sb, int max); [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT r); [StructLayout(LayoutKind.Sequential)] public struct RECT { public int L, T, R, B; } public static List Results = new List(); public static HashSet Pids = new HashSet(); public static void Run(uint[] pids) { Pids = new HashSet(pids); EnumWindows((h, l) => { uint pid; GetWindowThreadProcessId(h, out pid); if (Pids.Contains(pid) && IsWindowVisible(h)) { var t = new StringBuilder(256); GetWindowText(h, t, 256); var c = new StringBuilder(256); GetClassName(h, c, 256); RECT r; GetWindowRect(h, out r); int w = r.R - r.L, hh = r.B - r.T; if (w > 200 && hh > 200) { Results.Add(string.Format("hwnd=0x{0:x} pid={1} class={2} title={3} size={4}x{5} pos=({6},{7})", h.ToInt64(), pid, c, t, w, hh, r.L, r.T)); } } return true; }, IntPtr.Zero); } } "@ $pids = (Get-Process | Where-Object { $_.ProcessName -match 'MuMu|Nemu' }).Id | ForEach-Object { [uint32]$_ } Write-Output ("PIDs: " + ($pids -join ',')) [WinEnum2]::Run($pids) [WinEnum2]::Results | ForEach-Object { Write-Output $_ } if (-not [WinEnum2]::Results.Count) { Write-Output 'NO-WINDOWS' }