我想創建一個腳本來打開Internet Explorer瀏覽器,但有一些限制。該腳本驗證iexplorer.exe
進程是否正在運行,如果沒有(表示瀏覽器已關閉),則在10秒後自動重新打開該進程。爲什麼我無法重新打開瀏覽器(對象)?
這是腳本:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("Wscript.Shell")
Set objExplorer = CreateObject("InternetExplorer.Application")
Const REOPEN_AFTER =10000
objExplorer.Navigate "http://www.google.com"
objExplorer.Visible = true
objExplorer.ToolBar = false
objExplorer.MenuBar = false
objExplorer.StatusBar = false
objExplorer.AddressBar = true
objExplorer.Width = 1280
objExplorer.Height = 1024
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Resizable = false
Do While True
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'iexplore.exe'")
If colProcesses.Count = False Then
objExplorer.Navigate "http://www.google.com"
objExplorer.Visible = true
End If
Wscript.Sleep REOPEN_AFTER
Loop
如果我開始運行時,它打開瀏覽器腳本,但如果我關閉它,它不會重新打開它。
但是,如果我像這樣運行它,然後它的工作原理:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject("Wscript.Shell")
Set objExplorer = CreateObject("InternetExplorer.Application")
Const REOPEN_AFTER =10000
objExplorer.Navigate "http://www.google.com"
objExplorer.Visible = true
objExplorer.ToolBar = false
objExplorer.MenuBar = false
objExplorer.StatusBar = false
objExplorer.AddressBar = true
objExplorer.Width = 1280
objExplorer.Height = 1024
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Resizable = false
Do While True
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'iexplore.exe'")
If colProcesses.Count = 0 Then
objShell.Run "iexplorer.exe"
End If
Wscript.Sleep REOPEN_AFTER
Loop
有人能看到的錯誤是什麼?