首次提交
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
Add-Type @"
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class Win32Helper {
|
||||
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool IsWindowVisible(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern int GetWindowTextLength(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern int GetWindowText(IntPtr hWnd, System.Text.StringBuilder lpString, int nMaxCount);
|
||||
|
||||
public static List<IntPtr> GetProcessWindows(uint processId) {
|
||||
List<IntPtr> windows = new List<IntPtr>();
|
||||
EnumWindows(delegate(IntPtr hWnd, IntPtr lParam) {
|
||||
uint id;
|
||||
GetWindowThreadProcessId(hWnd, out id);
|
||||
if (id == processId && IsWindowVisible(hWnd) && GetWindowTextLength(hWnd) > 0) {
|
||||
windows.Add(hWnd);
|
||||
}
|
||||
return true;
|
||||
}, IntPtr.Zero);
|
||||
return windows;
|
||||
}
|
||||
|
||||
public static string GetWindowTextStr(IntPtr hWnd) {
|
||||
int length = GetWindowTextLength(hWnd);
|
||||
if (length == 0) return "";
|
||||
System.Text.StringBuilder builder = new System.Text.StringBuilder(length + 1);
|
||||
GetWindowText(hWnd, builder, builder.Capacity);
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
$ppts = Get-Process -Name "wpp", "POWERPNT", "wps" -ErrorAction SilentlyContinue
|
||||
foreach ($p in $ppts) {
|
||||
Write-Host "Process $($p.Id) $($p.ProcessName)"
|
||||
$hwnds = [Win32Helper]::GetProcessWindows($p.Id)
|
||||
foreach ($hwnd in $hwnds) {
|
||||
$title = [Win32Helper]::GetWindowTextStr($hwnd)
|
||||
Write-Host " HWND: $hwnd, Title: $title"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user