You are currently offline, waiting for your internet to reconnect

HOW TO: Determine If Screen Saver Is Running by Using Visual Basic 6.0

This article was previously published under Q315725
This article has been archived. It is offered "as is" and will no longer be updated.
This article demonstrates how to detect if a screen saver is running by using Visual Basic 6.0. In this sample, you use the SystemParametersInfo function and specify the SPI_GETSCREENSAVERRUNNING parameter.

back to the top


The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
  • Microsoft Windows XP, Microsoft Window Millennium Edition (Me), Microsoft Windows 2000, or Microsoft Windows 98 (see the References section for articles that relate to earlier versions of Windows)
In addition, this article assumes that you have Visual Basic 6.0 programming experience.

back to the top

Create an Application That Determines Screen Saver State

  1. Start Visual Basic 6.0, and then create a new Standard EXE project. Form1 is created by default.
  2. Add a Timer control to Form1, and then set the Interval property of the Timer to 1000. This interval represents one second.
  3. Right-click the form, and then click View Code. Add the following code to the General Declarations section of Form1's module:
    Option ExplicitPrivate Declare Function SystemParametersInfo _    Lib "user32" _    Alias "SystemParametersInfoA" _      (ByVal uiAction As Long, _       ByVal uiParam As Long, _       pvParam As Any, _       ByVal fWInIni As Long) As BooleanPrivate Const SPI_GETSCREENSAVEACTIVE As Long = &H10Private Const SPI_GETSCREENSAVERRUNNING As Long = &H72					
  4. Define a form-load handler procedure for your form. Add the following code, which displays a caption to indicate whether the screen saver is active:
    Private Sub Form_Load()    Dim bActive As Boolean        ' Find out if screen saver is active, and display a suitable message.    SystemParametersInfo SPI_GETSCREENSAVEACTIVE, 0, bActive, False    If bActive Then        Me.Caption = "Screen saver is active"    Else        Me.Caption = "Screen saver is not active"    End IfEnd Sub					
  5. Define a timer-event handler procedure for the timer. This event occurs once every second. Add the following code to this procedure, which produces a sound if the screen saver is running:
    Private Sub Timer1_Timer()    Dim bRunning As Boolean    ' Beep if the screen saver is running.    SystemParametersInfo SPI_GETSCREENSAVERRUNNING, 0, bRunning, False    If bRunning Then        Beep    End IfEnd Sub					
back to the top

Verify That It Works

  1. If a screen saver is not enabled on the computer, follow these steps to enable a screen saver:
    1. Right-click in the desktop, and then click Properties.
    2. In the Display Properties dialog box, on the Screen Saver tab, select a screen saver. Wait for approximately one minute, and then click OK.
  2. Build and run your Visual Basic application. The form caption in your application displays the following message:
    Screen saver is active
    NOTE: If the caption displays the "Screen saver is not active" message, the screen saver is not enabled.
  3. Wait for the screen saver to begin running. You hear short beeps at one-second intervals until the screen saver stops.
  4. Close your Visual Basic application.
  5. Reset the screen saver to your settings as appropriate.
back to the top


  • This application only calls SystemParametersInfo with the SPI_GETSCREENSAVEACTIVE parameter when the application starts to run. If the user changes the screen saver settings after this time, this information is not updated in the Visual Basic application.
  • Earlier versions of Windows, such as Microsoft Windows NT 4.0 and Microsoft Windows 95, do not support the SPI_GETSCREENSAVERRUNNING parameter to SystemParametersInfo. If you want to determine if a screen saver is running on these earlier versions of Windows, refer to the References section.
back to the top
For additional information about a low-level technique that uses the Windows C application programming interface (API) and message hooks, click the article number below to view the article in the Microsoft Knowledge Base:
238882 HOWTO: Know When Your Screen Saver Starts
For additional information about an alternative technique for Windows NT 4.0, click the article number below to view the article in the Microsoft Knowledge Base:
150785 INFO: Detect if a Screen Saver Is Running on Windows NT
For additional information about how to determine which version of 32-bit Windows you are running, click the article number below to view the article in the Microsoft Knowledge Base:
189249 HOWTO: Determine Which 32-Bit Windows Version Is Being Used
back to the top
poll screen saver state

Article ID: 315725 - Last Review: 12/07/2015 08:36:29 - Revision: 1.0

Microsoft Visual Basic 6.0 Professional Edition, Microsoft Visual Basic 6.0 Enterprise Edition

  • kbnosurvey kbarchive kbhowto kbhowtomaster kbapi KB315725