2010-02-14 75 views
3

我正在尋找一種方法來檢測和關閉與VBScript打開系統消息框。VBScript檢測打開的消息框並關閉它

使用下面的腳本,我可以把消息發送到前臺,並關閉它:

set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.AppActive "System Settings Change" 
WshShell.SendKeys "%N" 

問題:我需要一種方法,如果一個消息是使用VBsciprt這樣我就可以等待用戶交互檢測關閉它。

Thnak you。

回答

2

下面的腳本將完全按照我的要求進行。

' Will loop forever checking for the message every half a second 
' until it finds the message then it will send Alt-N and quit. 

Set wshShell = CreateObject("WScript.Shell") 

Do 
    ret = wshShell.AppActivate("System Settings Change") 
    If ret = True Then 
     wshShell.SendKeys "%N" 
     Exit Do 
    End If 
    WScript.Sleep 500 
Loop 
0

由於您有激活和關閉消息框的代碼,所以我猜測無論您正在做什麼都可能會導致消息框出現,並且您需要一種方法來清除它。

一種方法是啓動第二個腳本,該腳本只包含一個循環,用於監視消息框並在找到該消息時關閉它。您可以將其編碼爲在完成主腳本一段時間後超時。