-
-
Save 404neko/daabfcfb32f083db00675e778b4594fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install pywin32 | |
import ctypes | |
from ctypes import c_char | |
from win32process import GetWindowThreadProcessId | |
from win32gui import GetForegroundWindow | |
handle_Psapi = ctypes.WinDLL('Psapi.dll') | |
handle_kernel32 = ctypes.windll.kernel32 | |
OpenProcess = handle_kernel32.OpenProcess | |
GetProcessImageFileName = handle_Psapi.GetProcessImageFileNameA | |
MAX_PATH = 260 | |
last_window_id = 0 | |
def print_image_path(buffer): | |
text = '' | |
for item in buffer: | |
if item!=b'\x00': | |
text+=item.decode() | |
if len(text)>0: | |
print([text]) | |
while True: | |
current_window_id = GetForegroundWindow() | |
if current_window_id!=last_window_id: | |
last_window_id = current_window_id | |
process_id = GetWindowThreadProcessId(current_window_id) | |
handle_process = OpenProcess(0x400, 0, process_id[-1]) | |
buffer = (c_char * MAX_PATH)() | |
GetProcessImageFileName(handle_process, buffer, MAX_PATH) | |
print_image_path(buffer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment