Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

detect screensaver in vb.net

Posted on 2009-04-06
2
Medium Priority
?
1,135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

705 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