Win32 API question - Postmessage and Win2K lock window

Mark Erikson markulus00 at yahoo.com
Mon Jul 29 16:35:26 EDT 2002


Hey, folks.  I've got a problem regarding the PyCwnd.PostMessage()
function behind the Windows 2000 lock window.  I know this is more of
an API question than a Python question, but figured it was worth
asking here just in case.

Basics of the issue:
I'm trying to automatically launch the Windows 2000 Defrag utility. 
While any user can launch it, the defrag function can only be
activated by an administrator.  By getting the window handle and
creating a PyCwnd from the handle, I can do PostMessage() to the
window and send WM_KEYUP and WM_KEYDOWN messages.  When run as an
administrator, I can successfully simulate the keystrokes needed to
start the defragmentation.  However, this needs to be run on other
users computers, most likely during lunch.  So, I've been working with
Win2K's "runas" utility.  It requires that a password actually be
typed in, though no input is visible.  Again, I can use PostMessage to
send simulated keystrokes to the Command Prompt window, runas
completes successfully, Defrag launches, and everybody's happy.  The
problem comes when I try to deal with people using the CTRL-ALT-DEL
"Lock Window" function, which absorbs any standard keyboard input
(which is why I'm using WM_KEYUP/DOWN instead of a more standard
SendKeys type deal).  If I'm just running Defrag, I can still
successfully use PostMessage() and activate it.  *IF*, on the other
hand, I launch Runas behind the lock window, *I cannot send the
keystrokes*.

I've looked at everything from using pipes to replace stdin to using
other Runas-type utilities (SU, sfImpersonator, etc) to using
WriteConsole() to too much other stuff to remember.  Nothing I've
experimented with has seemed to work.

So... does anyone have any ideas?  I just need to be able to simulate
keystrokes for a password to a Command Prompt window for which I have
a handle, BEHIND the Win2K lock window.  I'm open to any suggestions,
including stuff that I've looked at already (since it's quite possible
I missed something).

Thanks in advance!

Mark Erikson

markulus00 'at' yahoo 'dot' com



More information about the Python-list mailing list