Re: Acquiring process handle and convert it into PID

Michael C <[email protected]> Tue, 29 Nov 2016 14:54:23 -0800
Newsgroups gmane.comp.python.ctypes
Message-ID <CANyKM1hw+kMf80cfsamdTG8KyXRLbAurBB6CqB-+Ef_i_3Wcaw@mail.gmail.com>
i understand. This is my first email list. :)

On Tue, Nov 29, 2016 at 2:51 PM, Diez B. Roggisch <[email protected]> wrote:

> 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