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
388 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
[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
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
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 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

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 …
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.
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…
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…

707 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