Patrick Li wrote:
>
> I am trying to write a program that will perform some operation on the
> user's computer when the user launches a particular executable(s) on
> the computer and when the user closes them.
>
> One way to achieve this is by polling the process table periodically
> and checking to see if one of the running processes matches the
> executable name that I am looking for.  However, I would much prefer
> not polling so frequently as it seems to be a waste of user's system
> resource.
>
> Does anyone know if there is a way to hook a callback to windows where
> it will trigger my function when windows launches a particular
> program?  I think that would be the ideal thing to do if that is
> available.

You can implement a system-wide WH_CBT hook, and watch for events like
HCBT_ACTIVEATE or HCBT_CREATEWND or HCBT_DESTROYWND.  However, remember
that a system-wide hook causes your DLL to be injected into every
running process, and gets involved with EVERY window message for EVERY
process.  It's not clear to me that it will have less of an impact on
performance than a periodic scan of the process table.

Also, you aren't going to be able to write such a hook in Python.  A
hook procedure lives in a very restricted environment, because you are
actually executing inside another process.  You can't even reliably
allocate memory.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to