Win32 API question - Postmessage and Win2K lock window

djw dwelch91 at nospam.attbi.com
Tue Jul 30 00:59:42 EDT 2002


Mark Erikson wrote:
> 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

I've tried automating things on Windows like this before with very
mixed results. I would recommend trying to run the app with a command
line or using a COM automation interface before attempting throwing
keystrokes at it. A collegue has had quite a bit of luck using the
Windows Scripting Host to do this sort of thing. Each of these (well,
at least running the app with CreateProcess()) has a "place" to stick
in security SIDs and DACLS and such that should let you get around
the administrator requirement. I would hit MSDN with some searches
and cross your fingers...

Good luck,

Don




More information about the Python-list mailing list