2016-07-28 127 views
1

當我關閉Windows資源管理器時,如何停止腳本運行?這是我的代碼。VBScript:關閉Windows資源管理器時停止腳本

Dim i 
    CreateObject("Wscript.Shell").Run """website1.com""", 0, False 
    Wscript.Sleep 40000 
    CreateObject("Wscript.Shell").Run """website2.com""", 0, False 
    Wscript.Sleep 40000 

For i=1 to 10 
    Set WshShell = WScript.CreateObject("WScript.Shell") 
    WshShell.AppActivate "Internet Explorer" 
    WshShell.SendKeys "{F5}" 
    Wscript.Sleep 1000 
    WshShell.SendKeys "^{TAB}" 
    Wscript.Sleep 40000   
Next 

回答

0

此計算感興趣的窗口數量和存在時0

Set objShell = CreateObject("Shell.Application") 
Do 
    Set AllWindows = objShell.Windows 
    Count = 0 
    For Each window in AllWindows 
     window.refresh2 3 
     Count = Count + 1 
    Next 
    If Count = 0 then Exit Do 
    Wscript.sleep 5000 
Loop 

或者刷新只有兩個窗口

Set objShell = CreateObject("Shell.Application") 
Do 
    Set AllWindows = objShell.Windows 
    Count = 0 
    For Each window in AllWindows 
     If window.locationname = "website1.com" or window.locationname = "website2.com" then 
      window.refresh2 3 
      Count = Count + 1 
     End If 
    Next 
    If Count = 0 then Exit Do 
    Wscript.sleep 5000 
Loop