[python-win32] handle is invalid?

sudheer sivathasan sudheer_87 at hotmail.com
Tue Jul 21 11:17:23 CEST 2009

Hey guys,


Another quick question. I'm still trying to do the thing in the email below. But this time im trying to use the win32api.GetModuleFileName function. It requires a PyHandle as an input which I think I've managed to get by using the function handle = w.FindWindow(0,str(w.GetWindowText(w.GetForegroundWindow()))) where handle would serve as the input to the win32api.GetModuleFileName function and w = win32gui. However I'm getting a 'the handle is invalid' error. Something I'm doing must be wrong. I figure if I can get the filename associated with the open window, I can just run a search for it through python. I'm sure there is an easier way to perform the stuff in the email below though. Could any of you guys please help me out with this? Thanks.






PS: Is there a way to use GetFullPathName to find the path of the .exe file?

From: sudheer_87 at hotmail.com
To: python-win32 at python.org
Subject: Trying to grab exe of foreground window
Date: Tue, 21 Jul 2009 10:48:19 +0800

Hi guys, 

Normally I’m able to find the answers I’m looking for on the net…but this time, either I haven’t searched hard enough or no one has attempted this before, so I would really like to request some help with this. I’m trying to write a program to locate the directory of the .exe of the foreground window and search for a file within that directory...I know this sounds ambitious but I believe there has to be a way to do it. So far, all I've managed to do is grab the name of the foreground window. Oh yeah, I'm pretty new to python actually...about 3 weeks into learning it. Any help you guys can provide would be greatly appreciated!! 

With Windows Live, you can organize, edit, and share your photos.

check out the rest of the Windows Live™. More than mail–Windows Live™ goes way beyond your inbox. More than messages
With Windows Live, you can organize, edit, and share your photos.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20090721/4f9abb74/attachment.htm>

More information about the python-win32 mailing list