Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ctypes import *
- import pythoncom
- import pyHook
- import win32clipboard
- user 32 = windll.user32
- kernel32 = windll.kernel32
- psapi = windll.psapi
- current_window = None
- def get_current_process():
- #uchwyt do pierwszoplanowego okna
- hwnd = user32.GetForegroundWindow()
- #sprawdzanie identyfikatora procesu
- pid = c_ulong(0)
- user32.GetWindowThreadProcessId(hwnd, byref(pid))
- #zapisanie identyfikatora bieżącego procesu
- process_id = "%d" %pid.value
- #pobranie pliku wykonywalnego
- executable = create_string_buffer("\x00" * 512)
- h_process = kernel32.OpenProcess(0x400 | 0x10, False, pid)
- psapi_GetModuleBaseNameA(h_process, None, byref(executable), 512)
- #odczytanie jego tytułu
- window_title = create_string_buffer("\x00" * 512)
- length = user32.GetWindowTextA(hwnd, byref(window_title), 512)
- #wydruk nagłówka, jeśli jesteśmy w odpowiednim procesie
- print
- print "[ PID: %s - %s - %s ]" (process_id, executable.value, window_title.value)
- print
- #zamknięcie uchwytów
- kernel32.CloseHandle(hwnd)
- kernel32.CloseHandle(h_process)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement