The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


How to Automatically Dismiss Popups from a Windows Service

Outlook Security Popup

Why Windows Services Should Avoid Showing Popups/Dialog Boxes

Unlike a regular application (like Microsoft Word) that you launch from a desktop icon and actively work with to accomplish a specific task, a Windows Service is designed to start when your computer boots and run entirely in the background — even if you never log on.

Yet despite this design philosophy, there is no restriction that actually prevents a Windows Service from displaying windows and trying to interact with users logged on to the PC. Indeed, such “Interactive Services” were encouraged in Windows XP and Windows Server 2003, but Microsoft changed their tune in Windows Vista. In our opinion, a couple of glaring problems caused the folks in Redmond to reverse course and actively discourage Windows Services from trying to get the desktop user’s attention:

  1. What happens when no one is logged on?

    It is unclear what should happen when a Windows Service shows a prompt and no user is there to answer it. Holding up the action while waiting for someone to log on and click a button can be problematic for tasks designed to perform important tasks, 24/7.

  2. What happens when several users are logged on?

    When a service throws up a prompt, which of the multiple users logged on should be allowed to respond to that window? One? All?

These thorny issues should discourage anyone from writing an interactive service today!

But what is you have inherited a legacy service implemented under the more permissive Windows XP or Server 2003 rules? What if commercial realities force you to run an interactive application as a windows service with a service wrapper like AlwaysUp? How do you keep those services running without interruption, getting around annoying prompts that would otherwise stall an important process?

Three Ways to Automatically Dismiss Dialog Boxes and Popups

  1. Write a Custom AutoIt Script

    AutoIt is a free scripting language designed for automating the Windows GUI. With this powerful tool, you can easily write scripts to activate windows, click buttons, check boxes, enter text and much more.

    For example, this AutoIt script clicks the “OK” button on a window named “OCR Error”:

    ; Try to bring the window to the top, to
    ; prepare it for input.
    WinActivate("OCR Error");
     
    ; Click the OK button in the window.
    ControlClick("OCR Error", "OK", "");
    

    Note that an AutoIt script can be compiled into an executable to run on any machine — even those without AutoIt installed.

  2. Buy Buzof, the “Annoying Windows Eliminator”

    Buzof is a commercial utility that makes it easy for non-programmers to automatically answer Windows prompts. Its point and click interface enables you to “train” the software to take the appropriate action on those annoying popups. Here is what Buzof looks like when configured to watch for four popups, clicking the “Yes” or “No” buttons:

    Buzof

    Note that Buzof is really meant for clicking buttons and other simple actions. More complex situations, such as checking a box and subsequently clicking a button or typing in a user name, are beyond its abilities.

  3. Develop your own Windows GUI Utility

    If you are an experienced Windows programmer, then it won’t be too difficult to create your own solution. This may be a good investment of your time if using AutoIt or purchasing Buzof are not viable options.

How to Run your Automated Solution on the Isolated Session 0 Desktop

Once you have settled on a method to automatically dispatch the dialog boxes and popups, you must now set it up to run on the desktop where Windows Services run — in Session 0. There are a couple of ways to achieve this:

  1. Run your Utility as a Windows Service

    We recommend using our AlwaysUp application to run your chosen utility as a Windows Service. If you are using an AutoIt script, set it up to run periodically, perhaps once every minute. For Buzof, which should be started once and kept running continuously, any service wrapper (such as Microsoft’s Srvany) will perform the basic job.

  2. Run your Utility with the Task Scheduler

    Setup a basic scheduled task to start your solution. It will run entirely in Session 0.

Note that you can also launch your utility manually in Session 0 using Microsoft’s PsExec command line tool.

Best of luck keeping your Windows Services operating 24×7, without annoying interruptions!

Posted in Windows Services | Tagged , , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *