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

x
?
Solved

How To Read The Screensaver Timer

Posted on 2006-07-03
7
Medium Priority
?
231 Views
Last Modified: 2008-02-01
Hello,

In VB 6, running under Windows 2000 or XP, how can one read the timer that the screensaver uses to determine how long it has been since the last user-generated activity. I realize a VB program could have its own timer, but ideally this program would not need to be running constantly, as a screensaver would. Rather it could execute, report (e.g. write to a log file), and close, whether running from the task scheduler, or remotely.

If the same could be accomplished with a .bat file, without resorting to VB, that would be just as good, if not better.

Thanks in advance,

s1m0ne
0
Comment
Question by:s1m0ne
[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
7 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 400 total points
ID: 17034384
0
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 400 total points
ID: 17036546
Another approach is to get the screen saver timeout value. Once your armed with this value you can then use BeginIdleDetection API.  Since SystemParametersInfo API gives the screen saver timeout in seconds and BeginIdleDetection uses minutes we need to simply convert the seconds to minutes then pass it to our procedure. You might be notified 2-3 seconds early about when the screen saver is about to run, this is simply due to the messaging going on in the background. Basically as you pass the minute into the procedure it will detect when you become idle and wait for that duration. Once the duration is up it singnals the callback procedure. This callback fires once per action meaning it will poll endlessley about when you become idle and when you become active again, each time reseting itself.

'-------- Module1.bas ----------

Option Explicit

'Msidle define
Private Const USER_IDLE_BEGIN = 1
Private Const USER_IDLE_END = 2

'SystemParametersInfo define
Private Const SPI_GETSCREENSAVETIMEOUT = 14

Private Declare Function BeginIdleDetection Lib "Msidle.dll" Alias "#3" ( _
    ByVal pfnCallback As Long, _
    ByVal dwIdleMin As Long, _
    ByVal dwReserved As Long) As Long

Private Declare Function EndIdleDetection Lib "Msidle.dll" Alias "#4" ( _
    ByVal dwReserved As Long) As Long

Private Declare Function SystemParametersInfoA Lib "user32" ( _
    ByVal uAction As Long, _
    ByVal uParam As Long, _
    ByRef lpvParam As Any, _
    ByVal fuWinIni As Long) As Long

Public Function ScreenSaverTime() As Long
    Dim SvrSeconds  As Long
    SystemParametersInfoA SPI_GETSCREENSAVETIMEOUT, 0&, SvrSeconds, 0&
    ScreenSaverTime = SvrSeconds
End Function

Public Sub BeginIdle(IdleMin As Long)
    If BeginIdleDetection(AddressOf IdleCallBack, IdleMin, 0&) = 0 Then
        Debug.Print "Success - BeginIdleDetection"
    End If
End Sub

Public Sub EndIdle()
    If EndIdleDetection(0&) Then
        Debug.Print "Success - EndIdleDetection"
    End If
End Sub

Public Sub IdleCallBack(ByVal dwState As Long)
    Select Case dwState
        Case USER_IDLE_BEGIN
           Form1.List1.AddItem "Screen saver activated ---  " & Time
        Case USER_IDLE_END
           Form1.List1.AddItem "Screen saver deactivated ---  " & Time
    End Select
End Sub



'------- Form1 --------

'Add 1 Listbox
'Add 1 Command button
'When you close the form close it by X button and not the VB IDE stop button.

Option Explicit

Private Sub Command1_Click()
   
    Dim arg As Long
   
    arg = ScreenSaverTime   ' get screen saver run time
    arg = (arg / 60)        ' seconds to minutes for idle
    BeginIdle arg           ' set up the callback to let us know
   
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    EndIdle                 ' stop callback and idle detection
End Sub
0
 
LVL 41

Expert Comment

by:graye
ID: 17039345
I'd agree that the GetLastInputInfo API is the way to go, but you won't be able to do this remotely... it must be run from the local PC
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:s1m0ne
ID: 17125621
Thanks. Sorry for the (continuing) delay. I got the first example working. I'll try to do the second one in the next couple days, for comparison. Ideally, something like this could be run as a service, but that may be beyond the scope of this question.
0
 
LVL 1

Author Comment

by:s1m0ne
ID: 17265471
Still working on it ...
0
 
LVL 1

Author Comment

by:s1m0ne
ID: 17657423
Sorry for letting this drag on so long. I'm splitting the points evenly between BlueDevilFan and egl1044. Thanks to all.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

704 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