Excellent...it works! Thanks...I put in the first sleep so I could test
the program with various other applications, so it'd give me enough time to
open up internet explorer or something...the second sleep was a
typo...leftover from a bit of earlier code i did. 
      I see...I tried looking for documentation onw win32con to see what I
needed but I couldn't muster up anything. All i got were
win32con.PROCESS_TERMINATE and process query information so I assumed one of
this was what I needed. Again...thanks so much for enlightening me.

Sudheer


Tim Roberts wrote:
> 
> reehdus wrote:
>> I tried that but I get stuck at EnumProcessModules. It tells me my access
>> is
>> denied. I'm not sure if I'm doing it right. My code is below:
>>
>> import win32gui
>> import win32api
>> import win32con
>> from time import sleep
>> import win32process
>>
>> sleep(2)
>> name = win32gui.GetForegroundWindow()
>> t,p = win32process.GetWindowThreadProcessId(name)
>> handle = win32api.OpenProcess(1,False,p)
>>   
> 
> The 1 there means PROCESS_TERMINATE.  That means you are only asking for
> permission to terminate the process, not to enumerate its contents.  For
> EnumProcessModules, you need PROCESS_QUERY_INFORMATION and
> PROCESS_VM_READ, which would be 0x0410.
> 
>> sleep(1)
>> whee = win32process.EnumProcessModules(handle)
>> nama = win32process.GetModuleFileNameEx(whee, 0)
>> print nama
>>   
> 
> Why are those "sleeps" in there?
> 
> EnumProcessModules returns a tuple, containing all of the modules
> currently loaded in the process.  You would need to choose one. 
> However, in this particular case, you don't need that call at all. 
> GetModuleFileNameEx takes a process handle, plus a module handle, or "0"
> to mean the processes original exe.  So, you can replace those last four
> lines with:
>     print win32process.GetModuleFileNameEx( handle, 0 )
> 
> -- 
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.
> 
> _______________________________________________
> python-win32 mailing list
> python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Trying-to-grab-exe-of-foreground-window-tp24582049p24617345.html
Sent from the Python - python-win32 mailing list archive at Nabble.com.

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

Reply via email to