Created
June 13, 2017 14:31
-
-
Save anonymous/8a6386fb5d4a844ba318e973f3e99132 to your computer and use it in GitHub Desktop.
Close annoying windows.
This file contains hidden or 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
#!/usr/bin/env python3 | |
import time | |
import ctypes | |
annoying_list = [ | |
'Alerte de Symantec', | |
] | |
while True: | |
buffer_window = ctypes.c_char_p(bytes(200*4)) | |
handle_activewindow = ctypes.windll.user32.GetForegroundWindow() | |
ctypes.windll.user32.GetWindowTextA(handle_activewindow,buffer_window,200) | |
if str(buffer_window.value,'cp1252') in annoying_list: | |
pid = ctypes.c_int() | |
thread = ctypes.windll.user32.GetWindowThreadProcessId(handle_activewindow,ctypes.byref(pid)) | |
print('{} : Found annoying window «{}» with handle {:x}, created by thread {:x} of PID {}. sending WM_DESTROY..'.format( | |
time.strftime('%Y-%m-%d-%H-%M-%S'), | |
str(buffer_window.value,'cp1252'), | |
handle_activewindow, | |
thread, | |
pid, | |
)) | |
WM_CLOSE = 0x10 | |
ctypes.windll.user32.PostMessageA(handle_activewindow, WM_CLOSE, 0, 0) | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment