VBScript to detect an open messagebox and close it

vbscript

I'm looking for a way to detect and close an open system messagebox with VBScript.

Using the following script, I can bring the message to foreground and close it:

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

The Question: I need a way to detect if a messagebox is waiting user interaction using VBsciprt so I can close it.

Thnak you.

Best Solution

The script below will do exactly what I asked.

' 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