我无法触发自动关闭我的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浏览器。
答案 0 :(得分:0)
似乎问题在于本地htm文件。虽然我找不到解决方案,但我已将脚本改为HTA,现在效果很好:
Const SHOW_ACTIVE_APP = 1
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.Run ("filename.hta") &, SHOW_ACTIVE_APP, True
Wscript.Quit
<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>