[Python] 纯文本查看 复制代码 import time
import win32gui
import win32process
import win32api
import win32con
import win32security
import psutil
def get_active_window_process_name():
last_fore = None
while True:
fore = win32gui.GetForegroundWindow()
if fore != last_fore:
last_fore = fore
tid, pid = win32process.GetWindowThreadProcessId(fore)
try:
process = psutil.Process(pid)
process_name = process.name()
username = process.username()
process_path = process.exe()
except Exception as e:
process_name = "N/A"
username = "N/A"
process_path = "N/A"
print(f"Process Name: {process_name}, Username: {username}, Process Path: {process_path}")
time.sleep(0.01)
if __name__ == "__main__":
get_active_window_process_name()
py语言写的,就是检测当前窗口是什么
最近老被弹回桌面,终于找到了元凶 |