Last active
November 28, 2017 10:04
-
-
Save dkw72n/35761923cdc150a8b84c23eb27b1f20c to your computer and use it in GitHub Desktop.
自动关闭 RTX 弹窗
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
import win32api, win32con, win32gui, win32process, win32com.client | |
import time | |
import sys | |
import traceback | |
CLOSE_WINDOW_INTERVAL = 0.1 | |
wmi = win32com.client.GetObject('winmgmts:') | |
def query_process_name_by_id(pid): | |
procs = wmi.ExecQuery('Select * from win32_process WHERE ProcessId=' + str(int(pid))) | |
if not procs: | |
return None | |
return procs[0].Name | |
def rtx_window_filter(hwnd): | |
if not hwnd: return False | |
clz = str(win32gui.GetClassName(hwnd)) | |
if not clz.startswith('Afx:') or not clz.endswith(':b:10005:0:0'): # r'Afx:[0-9a-fA-F]+:b:10005:0:0' | |
return False | |
tid, pid = win32process.GetWindowThreadProcessId(hwnd) | |
name = query_process_name_by_id(pid) | |
ret = name and 'rtx.exe' in name.lower() | |
if ret: | |
print "[+] matched window(%x) found: class=%s pid=%s name=%s" % (hwnd, clz, pid, name) | |
return ret | |
def close_window_no_throw(hwnd): | |
try: | |
print "[+] closing", hwnd | |
win32gui.PostMessage(hwnd,win32con.WM_CLOSE,0,0) | |
if CLOSE_WINDOW_INTERVAL: | |
time.sleep(CLOSE_WINDOW_INTERVAL) | |
except: | |
print "[!] exception raised while closing window(%d)" % hwnd | |
def window_closer(hwnd, wnd_fliter): | |
if wnd_fliter(hwnd): | |
close_window_no_throw(hwnd) | |
pass | |
def close_all_rtx_windows(): | |
win32gui.EnumWindows(window_closer, rtx_window_filter) | |
def auto_close_loop(interval): | |
while 1: | |
close_all_rtx_windows() | |
print "[+] wait %d seconds" % interval | |
time.sleep(interval) | |
if __name__ == '__main__': | |
try: | |
auto_close_loop(60) | |
except KeyboardInterrupt: | |
print "[-] interrupted" | |
sys.exit(0) | |
except: | |
traceback.print_exc() | |
sys.exit(-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment