How to Detect if Screensaver is active

I want to know if the screensaver is active.

I have continues polling that I want to turn off while the screensaver is active and resume the polling when the screensaver is deactivated.

I'm using vb.net express 2008 and Windows XP

Please advice.

Ola3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fabianbaptistaCommented:
You can use "user32.dll" and call SystemParametersInfo

you can see c# code here:
http://bytes.com/topic/c-sharp/answers/261540-detecting-screensaver-state

you can also see at:
http://www.vbforums.com/showthread.php?t=1280

hope this helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ola3Author Commented:
fabianbaptista,

Thanks!

I rewrote it to vb.net:


Public Class Form1

    Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, _
  ByVal uParam As Integer, ByRef lpvParam As Integer, ByVal fuWinIni As Integer) As Integer

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim SPI_GETSCREENSAVERRUNNING As Integer = 114
        Dim screenSaverRunning As Integer = -1

        Dim ok As Integer = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, screenSaverRunning, 0)

        If ok = 0 Then
            Debug.Write("Failed" & vbCrLf)
        ElseIf (screenSaverRunning = 0) Then
            Debug.Write("Screensaver OFF" & vbCrLf)
        Else
            Debug.Write("Screensaver ON" & vbCrLf)
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Timer1.Start()
    End Sub
End Class

Open in new window

fabianbaptistaCommented:
Great! excelent solution! :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.