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
Solved

VB Code: blcok access to apps after period of inactivity

Posted on 2006-11-03
7
239 Views
Last Modified: 2010-04-16
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
Comment
Question by:Dubs
  • 4
  • 3
7 Comments
 
LVL 35

Expert Comment

by:mvidas
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_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
 

Author Comment

by:Dubs
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

greg
0
 
LVL 35

Expert Comment

by:mvidas
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 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 

Author Comment

by:Dubs
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?

0
 
LVL 35

Accepted Solution

by:
mvidas earned 45 total points
ID: 17929831
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
 

Author Comment

by:Dubs
ID: 17929951
nice one,

thanks for this

greg
0
 
LVL 35

Expert Comment

by:mvidas
ID: 17929982
Glad 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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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…

856 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