How to Disable the Screen Saver Programmatically

Last reviewed: September 29, 1995
Article ID: Q126627
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
    

SUMMARY

Under Windows NT, you can disable the screen saver from your application code. To detect if the screen saver is enabled, use this:

   SystemParametersInfo( SPI_GETSCREENSAVEACTIVE,
                         0,
                         pvParam,
                         0
                       );

On return, the parameter pvParam will point to TRUE if the screen saver setting is enabled in the System control panel applet and FALSE if the screen saver setting is not enabled.

To disable the screen saver setting, call SystemParametersInfo() with this:

   SystemParametersInfo( SPI_SETSCREENSAVEACTIVE,
                         FALSE,
                         0,
                         SPIF_SENDWININICHANGE
                       );

MORE INFORMATION

When the screen saver is activated by the system, it is run on a desktop other than the user's desktop (similar to the login desktop displayed when no one is logged in). Therefore, you cannot use FindWindow() to determine if the screen saver is currently active.

Here are two methods that you can use to detect if the screen saver is currently running:

  1. Get the name of the current screen saver from the registry, parse the PE header of the screen saver binary to get the process name, then check for an active process with that name in the performance registry.

    -or-

  2. Write a screen saver that would be spawned by the system and would in turn spawn the "real" screen saver. The first screen saver could notify your application when the screen saver has been activated or deactivated.


Additional reference words: 3.50
KBCategory: kbgraphic
KBSubcategory: GdiScrsav


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.