VBScript,打开 IE,有时 visible=true 将其置于前台,有时不

VBScript, Open IE, sometimes visible=true brings it foreground, sometimes not

我正在尝试使用

打开 Internet Explorer
Set ie = createobject("InternetExplorer.Application")
ie.Navigate "www.google.com"
ie. Application.visible = true

奇怪的是,在某些设备上,新的 IE window 将在前台打开(最前面,成为活动 window)而其他人在半前台打开(通常是第二个,当最小化当前活动 window).

想知道是否有人知道造成差异的原因? 感谢任何帮助,提前致谢!

如果任何其他 windows 已最大化,IE window 将不会在前台打开。您可以尝试通过选择从不在任务栏上合并的图标来解决这个问题。

要确保在任何设备上激活 window,您可以使用 AppActivate:

Set objShell = WScript.CreateObject("WScript.Shell")
Set objIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
objie.navigate "www.google.com"
objIE.Visible = 1
objShell.AppActivate objIE

来自 Windows API 中 SetForegroundWindow 的帮助。

Remarks

The system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true:

•The process is the foreground process.

•The process was started by the foreground process.

•The process received the last input event.

•There is no foreground process.

•The process is being debugged.

•The foreground process is not a Modern Application or the Start Screen.

•The foreground is not locked (see LockSetForegroundWindow).

•The foreground lock time-out has expired (see
SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).

•No menus are active.

An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user

那么这意味着什么,如果前台程序启动了一个程序,那么新程序有两秒钟的时间来创建或激活一个 window,否则可能会失去该权利。