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
378 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now