0

I want to clear or automatically close popup windows through vbscript, but they may be different popup windows or may be a popup window within popup window. I am using a vbscript to create pop a window and I want a script which will automatically close all the popup windows. Below is the script which creates pop up windows and I want to close all these pop up windows through script.

Dim WshShell, BtnCode
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup("Do you like your job?", 7, "Answer This Question:", 4 + 32)
Select Case BtnCode
case 6 WScript.Echo "That's great!."
case 7 WScript.Echo "Sorry to hear that."
case -1 WScript.Echo "No Response?"
End Select

My solution to above code where it works partially:

Set wshShell = CreateObject("WScript.Shell") 

Do 
    ret = wshShell.AppActivate("Answer this question") 
    If ret = True Then 
        wshShell.SendKeys "%Y" 
        Exit Do
     End If 
    WScript.Sleep 500 
Loop 
avi
  • 1
  • 1
  • 3
  • Try [GUI for WSH VBS solution](https://stackoverflow.com/a/47111556/2165759) instead of popups. – omegastripes Mar 02 '18 at 18:52
  • well thanks for your reply but i want to clear that the above code is an example created by me to show pop up windows but what i am trying to do is that i want to clear or close pop up windows. In simple words i want to close popup windows automatically through vbscript if a pop generates in my application like warning or some error type popups which comes up and i want to clear those popup windows – avi Mar 02 '18 at 19:09
  • VBScript is not a best tool for that, take a look at AutoIt. – omegastripes Mar 02 '18 at 19:13
  • i know but i have to do it using vbscript..sorry but cant use autoit so i have to do using vbscript.Can ou help me with that – avi Mar 02 '18 at 19:17
  • You could have a second script running which detects the popup and uses `SendKeys` to interact with the popup – Dave Mar 02 '18 at 19:23
  • @Dave can't i use all in single one script and can you help me in finding the solution for it for the above problem which i have mentioned..i mean if you can help me in the script part it would be helpful.. – avi Mar 02 '18 at 20:12
  • 1
    Not with the `Wscript.Echo` statements - the `Popup` method you used in the initial messagebox has a timeout parameter that will dismiss the message box after your specified delay. Maybe use that? – Dave Mar 02 '18 at 20:34
  • @Dave that just a sample script to clear pop windows ut my main objective is to clear those windows through another script like in my application sometime some error or warnng popups comes so i have clear those popups.Below is the script which i tried ubt half work it oes it clears it but the last window it does not clear it so can you help me out with it.Set wshShell = CreateObject("WScript.Shell") Do ret = wshShell.AppActivate("Answer this question") If ret = True Then wshShell.SendKeys "%Y" Exit Do End If WScript.Sleep 500 Loop – avi Mar 03 '18 at 06:59
  • It sounds like you are trying to automate an application - if so, what tools are you using to do so? Secondly, if you are going to post code, please edit it into your question rather than in a comment where it's pretty much impossible to read easily. – Dave Mar 05 '18 at 15:40
  • @Dave yes i am trying to automate an application..right now i am just using vbscript to automate it..one of my appplication while running shows popup windows sometimes while its running so i need to clear those popup winodws or error mesgaes which it comes as pop up..and for that i am using vbscript in order to clear the popup window...i have posted my code too where it partially works.. – avi Mar 05 '18 at 18:09

0 Answers0