Link to home
Start Free TrialLog in
Avatar of AndrewBanfer
AndrewBanfer

asked on

Is there a way to determine if a computer has been inactive for a period of time in VB6?

I have an analytical instrument connected to a computer.  If we use the Windows Logout due to inactivity the analytical instrument stops acquiring data.

Is there a way to determine if a computer has been inactive for a period of time in Visual Basic 6?

This way we can make our own login screen and the analytical instrument continues to acquire data.
Avatar of clockwatcher
clockwatcher

GetLastInputInfo returns the last time that the system received input.  

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646302%28v=vs.85%29.aspx

The GetIdleSeconds call below will tell you how long in seconds the computer has been without user input.
 
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetLastInputInfo Lib "user32" (plii As Any) As Long
Private Type LASTINPUTINFO
    cbSize As Long
    dwTime As Long
End Type

Public Function GetIdleSeconds()

    Dim lii As LASTINPUTINFO
    lii.cbSize = Len(lii)
    Call GetLastInputInfo(lii)
    GetIdleSeconds = (GetTickCount() - lii.dwTime) / 1000

End Function

Open in new window

If you use the default screensaver option to require login after coming out of the screen saver mode then your program will continue to run. Just make sure that your power saving settings are set to never and never to ensure that the PC does not go into hibernation mode.
Avatar of AndrewBanfer

ASKER

Thanks Clockwatcher,  I will try it shortly.
ASKER CERTIFIED SOLUTION
Avatar of frankd
frankd
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
Thanks very much and have a great day!
Happy I was able to help.