Re: Kill process based on window name (win32)
Thank you Roger. Your advice did the trick. For anyone interested, the
basic code to terminate a process (politely) would be something like
this (hwnd is retrieved using win32gui.EnumerateWindows):
# Get the window's process id's
t, p = win32process.GetWindowThreadProcessId(hwnd)
# Ask window nicely to close
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
# Allow some time for app to close
time.sleep(10)
# If app didn't close, force close
try:
handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, p)
if handle:
win32api.TerminateProcess(handle,0)
win32api.CloseHandle(handle)
except:
pass:
Group items matching
in title, tags, annotations or url
1More
Kill process based on window name (win32) - 0 views
Doug Hellmann: PyMOTW: sys, Part 4: Exception Handling - 0 views
Managing Finances Gets Easier - 1 views
1 - 10 of 10
Showing 20▼ items per page