Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

detect screensaver in vb.net

Posted on 2009-04-06
2
Medium Priority
?
1,149 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:rettiseert
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 24083507
This worked for me...

Note that I'm using SPI_GETSCREENSAVERRUNNING and the third parameter is being passed ByRef instead of ByVal:
Public Class Form1
 
    Private Const SPI_GETSCREENSAVERRUNNING As Integer = &H72
    Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
        (ByVal uiAction As Integer, ByVal uiParam As Integer, ByRef pvParam As Integer, ByVal fWInIni As Integer) As Boolean
 
    Public Shared Function IsScreenSaverRunning() As Boolean
        Dim bRunning As Boolean
        SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, bRunning, False)
        Return bRunning
    End Function
 
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Form1.IsScreenSaverRunning Then
            My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
        End If
    End Sub
 
End Class

Open in new window

0
 
LVL 13

Author Closing Comment

by:rettiseert
ID: 31567311
Wonderful, thank you.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question