VB Code: blcok access to apps after period of inactivity

Posted on 2006-11-03
Last Modified: 2010-04-16

im still battleing my user base, many of whom have a mania for leaving machines logged on exposing my databases to all and sundry.

the IT dept have refused to create a new group in their group policy that will logout or lock the users who do this and my boss has refused my request to deny the repeat offenders access to my db's.

time to get tough.

i want to try and program a vb executable or embed vb into my applications (access mde's/ade's with an sql backend) which will detect if there has been no activity for a certain period and then deny them access to any of the apps i decide.

the db is for the school i work at and as part of the DPA we can't have all the contact, pastoral or academic info accesible by anyone and the only way i can stop this it seems is by using code that will detect periods of inactivity and then restrict access to that data.

and before any anyone ask no i can't simply ask the users to lock their machines they don't listen!!!

im waiting for an old question to be refunded so will up the points for this when it does.



Question by:Dubs
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
  • 4
  • 3
LVL 35

Expert Comment

ID: 17866207
Hi Greg,

You could use the getqueuestatus API to check for keyboard or mouse movement in the app:

Option Explicit
Private Declare Function GetQueueStatus Lib "user32" (ByVal fuFlags As Long) As Long
Private Const TIMEOUTSECONDS As Long = 3600
Private Const QS_KEY = &H1
Private Const QS_MOUSEMOVE = &H2
Private Const QS_MOUSEBUTTON = &H4
Private Const QS_INPUT = (QS_MOUSE Or QS_KEY)
Private bCancel As Boolean
Private Sub WaitForIdle(ByVal TimeOut_InSec As Long)
 Dim t As Double
 t = Timer
 Do While bCancel = False
  If GetQueueStatus(QS_INPUT) Then
   t = Timer
  End If
  If Timer - t >= TimeOut_InSec Then Exit Do
End Sub
Public Sub StartCheckingIdle()
 Do Until bCancel
  If bCancel = False Then Call AppWentIdle
  Do Until GetQueueStatus(QS_INPUT) Or bCancel
End Sub
Public Sub StopCheckingIdle()
 bCancel = True
End Sub
Private Sub AppWentIdle()
 'what to do when it goes idle
End Sub


Author Comment

ID: 17928734
do i run this as a module within my applications?

or ode sthis run as a code ij the backghround of windows?

just trying tow ork out how to deploy the code

LVL 35

Expert Comment

ID: 17929638
Hi Greg,

You would use it within your application.  How you want to use it is up to you, but I'll give you a suggestion:

-In Form_Load (or whatever your first procedure is), call StartCheckingIdle.  It will wait for a period of inactivity (TIMEOUTSECONDS constant, currently an hour), and when the app has been idle for that long it will call "AppWentIdle".
-In the AppWentIdle sub, call whatever routine you have to lock out the users.  You will want to put some kind of error checking in there to see if the user has access, as this will be fired every hour the user has been idle.
-In Form_Unload (or whenever you want the code to stop checking for idle users) call StopCheckingIdle to set the boolean cancel variable.

I adapted this code from and in looking there you can see that I changed it a little bit but the general idea is still there.  That was aimed more at a VB form than a standalone module though, if that helps at all.

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI


Author Comment

ID: 17929772
ah i see,

what i need to do is have something run outside of apps (if possible)

the users leave their machines on and i need code that will detect that this has been done (by calculating period of inactivity) and then deny access to all apps i specify..

is the above possible?

LVL 35

Accepted Solution

mvidas earned 45 total points
ID: 17929831
I've never had a need to do this, but it looks like the code at should be what you need.  Aside from simply killing the processes of the apps you want to lock out, I don't know how you'd do it from the outside like this (unless you can control them programmatically).

Author Comment

ID: 17929951
nice one,

thanks for this

LVL 35

Expert Comment

ID: 17929982
Glad to help!

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

630 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