Solved

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

Posted on 2013-06-02
6
382 Views
Last Modified: 2013-06-06
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.
0
Comment
Question by:AndrewBanfer
6 Comments
 
LVL 25

Expert Comment

by:clockwatcher
ID: 39215330
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

0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 39215434
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.
0
 

Author Comment

by:AndrewBanfer
ID: 39216407
Thanks Clockwatcher,  I will try it shortly.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 4

Accepted Solution

by:
frankd earned 500 total points
ID: 39216877
Rather than let an Inactive period period shut down or hibernate a computer or program I add a small program that moves the mouse a tiny bit every ten seconds or so.  That way it thinks someone is there, here is the VB6 code I use, that way it's all in my program, don't have to worry about the system.

Option Explicit

Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, _
                    ByVal dx As Long, ByVal dy As Long, _
                    ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Const MOUSEEVENTF_ABSOLUTE = &H8000

Private MouseX As Single
Private MouseY As Single


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _
                    x As Single, y As Single)
    MouseX = x
    MouseY = y
End Sub

Private Sub tmrTwitch_Timer() ' .Interval = 10,000 mSec
    'Move the mouse to where it was the last time MouseX, MouseY
    mouse_event MOUSEEVENTF_ABSOLUTE, MouseX, MouseY, 0, 0
End Sub
0
 

Author Closing Comment

by:AndrewBanfer
ID: 39225519
Thanks very much and have a great day!
0
 
LVL 4

Expert Comment

by:frankd
ID: 39226442
Happy I was able to help.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

810 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