Vbscript 在同一进程下为具有相同标题的窗口启用AppActivate函数
我使用一个非常简单的VBScript在多个屏幕之间切换并刷新,然后再暂停并继续,但是我想在其中两个屏幕之间切换的名称相同,请提供帮助Vbscript 在同一进程下为具有相同标题的窗口启用AppActivate函数,vbscript,Vbscript,我使用一个非常简单的VBScript在多个屏幕之间切换并刷新,然后再暂停并继续,但是我想在其中两个屏幕之间切换的名称相同,请提供帮助 Option Explicit Dim WshShell Set WshShell = WScript.CreateObject("WScript.Shell") Do WScript.Sleep 3000 WshShell.AppActivate("Inbox - Microsoft Outlook") WScript.Sleep 300
Option Explicit
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Do
WScript.Sleep 3000
WshShell.AppActivate("Inbox - Microsoft Outlook")
WScript.Sleep 3000
WshShell.AppActivate("CSE Task Monitor")
WSHShell.SendKeys "{F5}"
WScript.Sleep 3000
WshShell.AppActivate("website - Windows Internet Explorer")
WSHShell.SendKeys "{F5}"
Loop
谢谢大家。
Steve您应该使用ProcessId,而不是窗口标题。 我从exe文件名获取进程ID
Set WShell = CreateObject("WScript.Shell")
Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
wql = "SELECT ProcessId FROM Win32_Process WHERE Name = ProcessName.exe'"
i=0
For Each process In WMI.ExecQuery(wql)
ProcessIdArray(i) = process.ProcessId
i = i + 1
Next
现在,您有了相同ProcessName.exe的ProcessID数组,可以使用
WshShell.AppActivate(ProcessIdArray(0))
WScript.Sleep 3000
WshShell.AppActivate(ProcessIdArray(1))