0

I'm reading Black Hat Python and in chapter 8 I find "user32.GetWindowThreadProcessID(hwnd,byref(pid))" doesn't work, just like the picture shows.

It seems that python can't find GetWindowThreadProcessID, but it can find GetForegroundWindow which also is exported from user32.dll.

I also try "windll.LoadLibrary("user32.dll")", but it still doesn't work.

Thank you!

Z.Zander
  • 35
  • 7

1 Answers1

2

It should work if you your OS version is at least Windows 2000 Professional:

import ctypes
import ctypes.wintypes
pid = ctypes.wintypes.DWORD()
hwnd = ctypes.windll.user32.GetForegroundWindow()
print( ctypes.windll.user32.GetWindowThreadProcessId(hwnd,ctypes.byref(pid)) )
napuzba
  • 6,033
  • 3
  • 21
  • 32
  • Thank you, I have found the embarrassing problem that I mistakenly typed in "D" instead of "d" in "GetWindowThreadProcessId". – Z.Zander Oct 17 '16 at 02:57