本帖最后由 buyiyang 于 2023-3-21 16:30 编辑
这个问题我又琢磨了一下
ps1- $title = '海王星'
- $process = Get-Process | Where-Object {$_.MainWindowTitle -like "*{0}*" -f $title}
- if ($process) {
- $handle = $process.MainWindowHandle
- Add-Type @'
- using System;
- using System.Runtime.InteropServices;
- public static class User32 {
- [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd);
- [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- [DllImport("user32.dll")] public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
- }
- '@
- [void][User32]::SetForegroundWindow($handle)
- [void][User32]::ShowWindow($handle, 9)
- [User32]::keybd_event(17, 0, 0, 0)
- [User32]::keybd_event(77, 0, 0, 0)
- Start-Sleep -Milliseconds 50
- [User32]::keybd_event(77, 0, 2, 0)
- [User32]::keybd_event(17, 0, 2, 0)
- } else {
- Write-Host 没有找到有关 $title 的窗口
- Start-Sleep 2
- }
复制代码 vbs- Set WshShell = CreateObject("WScript.Shell")
- WshShell.AppActivate("海王星")
- WScript.Sleep(500)
- WshShell.SendKeys("^m")
复制代码
|