Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

VB Code: blcok access to apps after period of inactivity

Hi,

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.

cheers

greg

0
Dubs
Asked:
Dubs
  • 4
  • 3
1 Solution
 
mvidasCommented:
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_MOUSE = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
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
   DoEvents
  End If
  If Timer - t >= TimeOut_InSec Then Exit Do
 Loop
End Sub
Public Sub StartCheckingIdle()
 Do Until bCancel
  WaitForIdle TIMEOUTSECONDS
  If bCancel = False Then Call AppWentIdle
  Do Until GetQueueStatus(QS_INPUT) Or bCancel
   DoEvents
  Loop
 Loop
End Sub
Public Sub StopCheckingIdle()
 bCancel = True
End Sub
Private Sub AppWentIdle()
 'what to do when it goes idle
End Sub

Matt
0
 
DubsAuthor Commented:
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

greg
0
 
mvidasCommented:
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 http://www.freevbcode.com/ShowCode.Asp?ID=3297 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.

Matt
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
DubsAuthor Commented:
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?

0
 
mvidasCommented:
I've never had a need to do this, but it looks like the code at http://www.freevbcode.com/ShowCode.ASP?ID=3662 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).
0
 
DubsAuthor Commented:
nice one,

thanks for this

greg
0
 
mvidasCommented:
Glad to help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now