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
380 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 / DAO 3.6 / run time error: Couldn't find installable ISAM 7 74
Using "ScreenUpdating" 6 55
How to Add / Edit Windows Menu 4 51
How to make an ADE file by code? 11 79
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…

911 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

19 Experts available now in Live!

Get 1:1 Help Now