tags:

views:

241

answers:

2

Hi.

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.

A: 

Since you have the code to activate and close the messagebox, I'm guessing that whatever you are doing may or may not cause a messagebox to appear and you need a way to clear it if it does.

One method is to launch a second script that just contains a loop that watches for the messagebox and closes it when if finds it. You can code it to timeout after some amount of time that will allow the main script to complete.

aphoria
+1  A: 

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 
Leonid