Skip to content

Instantly share code, notes, and snippets.

Created June 13, 2017 14:31
Show Gist options
  • Save anonymous/8a6386fb5d4a844ba318e973f3e99132 to your computer and use it in GitHub Desktop.
Save anonymous/8a6386fb5d4a844ba318e973f3e99132 to your computer and use it in GitHub Desktop.
Close annoying windows.
#!/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