我使用的脚本是:
如何激活最小化的雷鸟消息框,知道其标题吗?
以下代码不起作用:
Set WshShell = CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("""C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe""")
WScript.Sleep 2000
WshShell.SendKeys("^n")
WScript.Sleep 500
PID = WshShell.AppActivate(WshExec.ProcessID)
WshShell.Run("notepad")
If PID Then
WshShell.SendKeys("^k")
Else
MsgBox "Nothing!"
End If
发布于 2019-12-07 17:35:59
VBS的AppActivate封装了API的SetForegroundWindow。您的程序必须符合下列规则之一才能设置活动窗口。注意,标准的锁定时间是2秒--这是大多数人被捕获的地方。注VBScript没有用户界面,所以不能成为前台窗口-在程序启动后,您有2秒的时间设置窗口。
来自https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow
SetForegroundWindow
备注
前台窗口是Z顺序顶部的窗口。它是用户正在使用的窗口。在先发制人的多任务处理环境中,通常应该让用户控制哪个窗口是前台窗口。
Windows 98/Me,Windows 2000/XP:系统限制哪些进程可以设置前台窗口。只有当下列条件之一为真时,进程才能设置前台窗口:
使用此更改后,当用户使用另一个窗口时,应用程序无法将窗口强制到前台。相反,SetForegroundWindow将激活窗口(参见SetActiveWindow),并调用FlashWindowEx函数通知用户。
https://stackoverflow.com/questions/59224620
复制相似问题