Link to home
Start Free TrialLog in
Avatar of rettiseert
rettiseert

asked on

detect screensaver in vb.net

Hi

I'm using VB.NET 2008 & WinForms. I need a function that returns True if the system screensaver is running.

I have tried this:

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

    Public Shared Function IsScreenSaverRunning() As Boolean
        Dim Running As Integer
        Const SPI_GETSCREENSAVEACTIVE As Integer = 16
        SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, Running, 0)
        Return Running
    End Function

But SystemParametersInfo returns an error value and after callin GetLastError I ger error 998 (Invalid access to memory location).

I guess the problem is with the API calling / passing parameters.

Any ideas?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rettiseert
rettiseert

ASKER

Wonderful, thank you.