Re: Acquiring process handle and convert it into PID
Michael C <[email protected]> Wed, 30 Nov 2016 08:15:20 -0800
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <CANyKM1j0SRAkvbUgBMBvJU-S0KO+H3P-RcvyvZyTATo3KK4muw@mail.gmail.com> |
if I still want to use Windll somehow, since I need windows API, how should I do it? thx On Wed, Nov 30, 2016 at 8:14 AM, Michael C <[email protected]> wrote: > Why is it a bad idea? > > On Wed, Nov 30, 2016 at 7:55 AM, eryk sun <[email protected]> wrote: > >> On Tue, Nov 29, 2016 at 10:07 PM, Michael C >> <[email protected]> wrote: >> > I ran this but the value returned was 0. I am trying to save time by >> > automating the PID acquisition process. >> > >> > import ctypes >> > import time >> > >> > time.sleep(2) >> > handle = ctypes.windll.user32.GetForegroundWindow() >> > print(handle) >> > PID = ctypes.windll.kernel32.GetProcessId(handle) >> > print (PID) >> >> GetProcessId is the wrong function. >> >> To begin with, before writing a single line of code, you need to >> familiarize yourself with the subject of WinAPI handles. Carefully >> read the following pages: >> >> Object categories >> https://msdn.microsoft.com/en-us/library/ms724515 >> User >> https://msdn.microsoft.com/en-us/library/ms725486 >> GDI >> https://msdn.microsoft.com/en-us/library/ms724291 >> Kernel >> https://msdn.microsoft.com/en-us/library/ms724485 >> >> Here's the function you'll need: >> >> GetWindowThreadProcessId >> https://msdn.microsoft.com/en-us/library/ms633522 >> >> Also, please stop using ctypes.windll. The global library loaders were >> an extremely bad idea. >> > > ------------------------------------------------------------------------------ _______________________________________________ ctypes-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ctypes-users