小智 5
要使用 WSH 获取它,您可以使用这篇 CodeProject 文章中找到的 COM DLL 。使用它,您可以像这样获取窗口句柄:
Set obj = CreateObject("APIWrapperCOM.APIWrapper")
winHandle = obj.FindWindow("test.txt - Notepad")
Run Code Online (Sandbox Code Playgroud)
这在PowerShell中也很容易。
例子:
(Get-Process powershell).MainWindowHandle
Run Code Online (Sandbox Code Playgroud)
此抓取是 PowerShell 进程的窗口句柄。
尽管如果您的主要目标是使窗口位于最顶层,但有很多程序可以实现此目的,例如DeskPins: