Skip to content

Instantly share code, notes, and snippets.

@romainthomas
Forked from anonymous/window.py
Created June 14, 2017 15:29
Show Gist options
  • Save romainthomas/59f76a1e1ff3d8b3f4070edce8418d7a to your computer and use it in GitHub Desktop.
Save romainthomas/59f76a1e1ff3d8b3f4070edce8418d7a 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