操作したいアプリケーションのタイトルとハンドルNoを見つける際、リストアップする
if (-not [System.Type]::GetType("User32_Helper")) {
Add-Type @"
using System;
using System.Text;
using System.Runtime.InteropServices;
public class User32_Helper {
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
public static void ListOpenWindows() {
EnumWindows(delegate (IntPtr hWnd, IntPtr lParam) {
if (IsWindowVisible(hWnd)) {
StringBuilder sb = new StringBuilder(256);
GetWindowText(hWnd, sb, sb.Capacity);
string title = sb.ToString();
if (!string.IsNullOrEmpty(title)) {
Console.WriteLine("Window Handle: " + hWnd + " Title: " + title);
}
}
return true;
}, IntPtr.Zero);
}
}
"@
}
[User32_Helper]::ListOpenWindows()
コメント