Re: Acquiring process handle and convert it into PID
"Diez B. Roggisch" <[email protected]> Tue, 29 Nov 2016 23:51:44 +0100
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Hello Michael, > I ran this but the value returned was 0. I am trying to save time by automating the PID acquisition process. > thx all > > > import ctypes > import time > > time.sleep(2) > handle = ctypes.windll.user32.GetForegroundWindow() > print(handle) > PID = ctypes.windll.kernel32.GetProcessId(handle) > print (PID) Not too surprisingly. A HANDLE is an opaque reference to *something*. Not everything that takes a HANDLE takes a HANDLE of any kind. Windows have HANDLEs, Processes have HANDLES, etc… So you are missing a step here from getting the foreground Window’s HANDLE to the process it belongs to. But truth be told: these are not ctypes questions. These are windows system programming questions. There are better places for this to ask. And please learn how to operate a mailing list. Answer & proper quote to emails instead of writing new ones for every sentence. It is impossible to follow. Diez ------------------------------------------------------------------------------ _______________________________________________ ctypes-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ctypes-users