倒计时后VBScript无法关闭启动的IE浏览器

时间:2017-02-28 08:38:15

标签: html internet-explorer vbscript countdown wsh

问题

我无法触发自动关闭我的VBS脚本打开的浏览器:

Set objShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2")
Set objIE = WScript.CreateObject("InternetExplorer.Application")

Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0)
For Each objItem in colItems
  intHorizontal = objItem.ScreenWidth
  intVertical = objItem.ScreenHeight
Next

objIE.Visible = 1
objIE.Navigate "D:\localpath\filename.htm"

objShell.AppActivate objIE

Do Until VarType(objIE) = 9
  WScript.Sleep 1000
  'For Each p In colItems
  'p.Terminate
  'Next

  'objIE.Quit
Loop
objIE.Quit
Set objIE = Nothing

当我尝试objIE.Quit时,我收到错误The object invoked has disconnected from its clients(80010108)。我尝试在断开连接之前调用该对象,但没有任何反应:

Do Until VarType(objIE) = 9
  WScript.Sleep 60000
  objIE.Quit
Loop

需要

我需要一个打开我的网页的脚本,进行1分钟的倒计时,然后关闭IE浏览器。

约束

  1. 不应该使用kill process
  2. 只应关闭正确的浏览器
  3. 不应使用JS,因为默认机器设置已禁用它们 一个。对于没有JS的倒计时,我在网页上使用gif作为解决方法
  4. htm必须是本地的。 objIE.Quit在htm在线托管时起作用

1 个答案:

答案 0 :(得分:0)

似乎问题在于本地htm文件。虽然我找不到解决方案,但我已将脚本改为HTA,现在效果很好:

VBS

Const SHOW_ACTIVE_APP = 1 
Set objShell = Wscript.CreateObject("Wscript.Shell") 
objShell.Run ("filename.hta") &, SHOW_ACTIVE_APP, True 
Wscript.Quit

HTA

<head>
<HTA:APPLICATION 
     APPLICATIONNAME="AppName"
     SINGLEINSTANCE="yes"
     SHOWINTASKBAR="no"  
     ICON="" 
     SCROLL="no"
     CAPTION="yes"
     >
    <style type="text/css">

    </style>

    <title>Information Security</title>
    <script language="VBScript">
        Sub Window_onLoad
            window.resizeTo 680,390
        End Sub 
    </script>
    <script type="text/javascript">
    </script>
</head>
<body>
    <!-- html content -->
</body>