python根据windows窗体句柄获取进程名和进程线程ID
依赖库:win32 ,psutil
参考代码代码:参考代码
实例代码
from win32 import win32process
import psutil
def test_windows_window():
app = win32gui.GetWindowText(67526)
if win32gui.IsWindowVisible(67526) and win32gui.IsWindowEnabled(67526):
thread_id, process_id = win32process.GetWindowThreadProcessId(67526)
process = psutil.Process(process_id)
print(process.name(), process_id)
proc = psutil.Process(pid=process_id )
print(proce.name())
print(app)