[Tutor] monitor other running applications with Python?
alan.gauld at btinternet.com
Sun May 27 16:54:11 CEST 2007
"Che M" <pine508 at hotmail.com> wrote
> Hi, searched a bit for this but haven't found much.
> Is it possible to use Python to monitor the use of
> other applications?
> At minimum, I wan't to know that the application was running
Thats fairly easy using OS tools such as ps on Unix.
You can dig a little deeper and use the system APIs such
as the proc fiilesystem or the equivalent in the windows
> better would be some sense of the use or content, such
> as whether the app was idle or the user was using it,
> or, for a web browser, what URLs were visited and for
> how long, etc.
Thats possible but gets very OS specific and very low level too.
On Windows you can catch Windows events and messages
using some of the raw Win32 API calls from the ctypes module.
(I've never used ctypes for anything this low level but it
should be possible, I''ve certainly done it in C++ and Delphi
on Win 9X). But its messy and fairly deep Windows magic
and you will need to spend a fair bit of time experimenting
and reading the docs on MSDN as well as the Win32 API
> Ideally I'd like a cross-platforms approach
I doubt if that's possible except at the process monitoring
level. For the kind of detail you want the bgestb you can
do is have a common UI and pluggable modules based
on the OS.
Also beware legal implications. There are issues around
personal privacy, data proptection etc and these vary between
countries (and even states in the US). People are increasingly
wary of Big Brother style monitoring. Detecting inappropriate
use of the internet across a corporate firwall is generally
considered OK but silently monitoring individuals brings you
into murky legal waters.
Finally, take a look at the stuff in the os package and the
syslog module for Unix.
Author of the Learn to Program web site
More information about the Tutor