Tell if Win2000 or XP is inactive

B

Bart Nessux

Hello,

Auditors want us to log out a user if the computer they are logged onto
has been unused/inactive for a set period of time. It's trivial to
logout the user, but we're having trouble telling if the system is
indeed inactive. If we could learn that information, then we'd need to
measure how long it has been like this so we can all the logout
function. How might this determination and measurement be approached?

We're using Python 2.3.x w/o Mr. Hammonds extra Windows extensions. We
do not want to install the win32 extensions.

Thanks,
Bart
 
L

Larry Bates

Why not just use screensaver that begins after your
"unused/inactive" time period and check the On resume,
password protect" box (XP). They have to log back in to
do anything. Doesn't really log them "out", but if they
have applications loaded, logging them out is going to
be difficult (e.g. what do you do with any dialogs that
may appear asking about unsaved work) and may not be what
you really want. This should "protect" the unattended
machine (which is what the auditors want) and your users.

HTH,
Larry Bates
Syscon, Inc.
 
B

Bart Nessux

I suggested this as well... the auditors say no. They want the users
logged out. I may push for this again though.
 
R

Richie Hindle

[Bart]
Auditors want us to log out a user if the computer they are logged onto
has been unused/inactive for a set period of time. It's trivial to
logout the user, but we're having trouble telling if the system is
indeed inactive. [...]

We're using Python 2.3.x w/o Mr. Hammonds extra Windows extensions. We
do not want to install the win32 extensions.

It's a bit weird to want to do Windows-specific things without installing
the win32 extensions. Would you be prepared to install ctypes and one extra
DLL? In that case I have a solution for you. If not, I don't believe it's
possible.

At http://www.codeproject.com/dll/trackuseridle.asp is an article on
tracking idle time. From the misleading-named "Download source files" link
you can download a zip file which includes IdleTrac.dll. Using ctypes you
can drive that DLL from Python like this:

---------------------------------------------------------------------------

import time
from ctypes import *

kernel32 = windll.kernel32
GetTickCount = kernel32.GetTickCount

# IdleTrac's API uses C++ mangled names. No bother.
IdleTrac = windll.IdleTrac
IdleTrackerInit = getattr(IdleTrac, "?IdleTrackerInit@@YAHXZ")
IdleTrackerTerm = getattr(IdleTrac, "?IdleTrackerTerm@@YAXXZ")
IdleTrackerGetLastTickCount = \
getattr(IdleTrac, "?IdleTrackerGetLastTickCount@@YAKXZ")

IdleTrackerInit()
for i in range(10):
idleDelta = float(GetTickCount() - IdleTrackerGetLastTickCount()) / 1000
print "Last input event was %.2f seconds ago." % idleDelta
time.sleep(1)
IdleTrackerTerm()
 
R

Richie Hindle

[Richie]
Would you be prepared to install ctypes and one extra DLL?

Ah! I hadn't spotted that you were running on Win2000+. In that case you
can do it with ctypes alone:

---------------------------------------------------------------------------

import time
from ctypes import *

GetTickCount = windll.kernel32.GetTickCount
GetLastInputInfo = windll.user32.GetLastInputInfo

class LASTINPUTINFO(Structure):
_fields_ = [("cbSize", c_uint),
("dwTime", c_uint)]

lastInputInfo = LASTINPUTINFO()
lastInputInfo.cbSize = sizeof(lastInputInfo)
for i in range(10):
GetLastInputInfo(byref(lastInputInfo))
idleDelta = float(GetTickCount() - lastInputInfo.dwTime) / 1000
print "Last input event was %.2f seconds ago." % idleDelta
time.sleep(1)
 
L

Larry Bates

The problem is that they don't always think all the way
through the implications of what they are asking you to
do. The workstation could have lots of "unsaved" work.
You can't just kill all the running applications, this
can have disastrous effects. You can't say yes to any
"Do you want to save your changes?" dialogs either.
It is even unclear what "idle" actually means. Does it
mean no keyboard/mouse activity in N minutes? What if
someone is running a long-running application, do you
kill the machine? With mail and other background apps
using CPU cycles in the background there's no way to tell
a long running accounting report from Outlook checking
for mail. Example: I have about 4-5 jobs set up in my
Windows scheduler that run unattended at night (Norton
Antivirus updates, pricelist downloads, etc). My
machine has normally been inactive for hours prior to
them running. If something logged me off the network
many of these jobs wouldn't run properly because they
need access to network resources. The screensaver solution
locks my machine to achieve security AND doesn't mess
with these background jobs.

Any solutions should take into account these possibilities.

Suggestion: I have seen a proximity badge that works with
Windows NT and above. If you walk away from the computer
too far, it triggers something forcing you to supply
a password for access. I don't remember the company, but
you should be able to Google for it. It would be expensive
I'm sure.

HTH,
Larry Bates
Syscon, Inc.
 
?

=?ISO-8859-1?Q?Andr=E9_Nobre?=

Larry said:
The problem is that they don't always think all the way
through the implications of what they are asking you to
do. The workstation could have lots of "unsaved" work.
You can't just kill all the running applications, this
can have disastrous effects. You can't say yes to any
"Do you want to save your changes?" dialogs either.
It is even unclear what "idle" actually means. Does it
mean no keyboard/mouse activity in N minutes? What if
someone is running a long-running application, do you
kill the machine? With mail and other background apps
using CPU cycles in the background there's no way to tell
a long running accounting report from Outlook checking
for mail. Example: I have about 4-5 jobs set up in my
Windows scheduler that run unattended at night (Norton
Antivirus updates, pricelist downloads, etc). My
machine has normally been inactive for hours prior to
them running. If something logged me off the network
many of these jobs wouldn't run properly because they
need access to network resources. The screensaver solution
locks my machine to achieve security AND doesn't mess
with these background jobs.

Any solutions should take into account these possibilities.

Suggestion: I have seen a proximity badge that works with
Windows NT and above. If you walk away from the computer
too far, it triggers something forcing you to supply
a password for access. I don't remember the company, but
you should be able to Google for it. It would be expensive
I'm sure.

HTH,
Larry Bates
Syscon, Inc.
This could work?
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52302
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,662
Latest member
salsusa

Latest Threads

Top