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, [email protected]
Providenza & Boekelheide, Inc.
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32