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
383 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

791 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