使用 vb 脚本时 IE 失去焦点

Focus lost for IE when using vb script

我正在尝试启动 IE 并将 calc.exe 路径作为 URL 传递并下载它。但是过了URL之后,WshShell的焦点就转移到了另一个点上。下面是我的脚本。

strWebSite = "file://C:/Windows/System32/calc.exe"
Set ie = GetObject ("", "internetexplorer.application")
ie.Navigate2 strWebSite
WScript.Sleep 500
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate("Internet Explorer")
WScript.Sleep 3000
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 3000
WshShell.SendKeys "{TAB}"
WScript.Sleep 3000
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"

已解决:通过进程 ID 激活 IE

strWebSite = "file://C:/Windows/System32/calc.exe"
Set ie = GetObject ("", "internetexplorer.application")
ie.Navigate2 strWebSite
WScript.Sleep 500
Set WshShell = WScript.CreateObject("WScript.Shell")
Set Processes = GetObject("winmgmts:").InstancesOf("Win32_Process")

intProcessId = ""
For Each Process In Processes
  If StrComp(Process.Name, "iexplore.exe", vbTextCompare) = 0 Then
      intProcessId = Process.ProcessId
      Exit For
   End If
Next
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate intProcessId 
WScript.Sleep 3000
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 3000
WshShell.SendKeys "{TAB}"
WScript.Sleep 3000
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"