Solved

How To Read The Screensaver Timer

Posted on 2006-07-03
7
225 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 100 total points
ID: 17034384
0
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 100 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
Independent Software Vendors: 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

734 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