Python win32process.TerminateProcess() Examples
The following are 12
code examples of win32process.TerminateProcess().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32process
, or try the search function
.
Example #1
Source File: process.py From peach with Mozilla Public License 2.0 | 6 votes |
def closeApp(self, hProcess, title): """ Close Application by window title """ try: win32gui.EnumWindows(FileWriterLauncherGui.enumCallback, title) if proc is not None: win32event.WaitForSingleObject(hProcess, 5 * 1000) win32api.CloseHandle(hProcess) for pid in self.genChildProcesses(proc): try: handle = win32api.OpenProcess(1, False, pid) win32process.TerminateProcess(handle, -1) win32api.CloseHandle(handle) except: pass except: pass
Example #2
Source File: process.py From peach with Mozilla Public License 2.0 | 6 votes |
def closeApp(self, hProcess, title): """ Close Application by window title """ try: win32gui.EnumWindows(FileWriterLauncherGui.enumCallback, title) if hProcess is not None: win32event.WaitForSingleObject(hProcess, 5 * 1000) win32api.CloseHandle(hProcess) for pid in self.genChildProcesses(proc): try: handle = win32api.OpenProcess(1, False, pid) win32process.TerminateProcess(handle, -1) win32api.CloseHandle(handle) except: pass except: pass
Example #3
Source File: winprocess.py From ironpython2 with Apache License 2.0 | 5 votes |
def kill(self, gracePeriod=5000): """ Kill process. Try for an orderly shutdown via WM_CLOSE. If still running after gracePeriod (5 sec. default), terminate. """ win32gui.EnumWindows(self.__close__, 0) if self.wait(gracePeriod) != win32event.WAIT_OBJECT_0: win32process.TerminateProcess(self.hProcess, 0) win32api.Sleep(100) # wait for resources to be released
Example #4
Source File: _dumbwin32proc.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def signalProcess(self, signalID): if self.pid is None: raise error.ProcessExitedAlready() if signalID in ("INT", "TERM", "KILL"): win32process.TerminateProcess(self.hProcess, 1)
Example #5
Source File: TestCmd.py From GYP3 with BSD 3-Clause "New" or "Revised" License | 5 votes |
def terminate(self): win32process.TerminateProcess(self._handle, 1)
Example #6
Source File: WindowsServer.py From pycopia with Apache License 2.0 | 5 votes |
def kill(self): handle = win32api.OpenProcess( win32con.PROCESS_VM_READ | win32con.PROCESS_TERMINATE, pywintypes.FALSE, self.childpid) win32process.TerminateProcess(handle, 3)
Example #7
Source File: _dumbwin32proc.py From learn_python3_spider with MIT License | 5 votes |
def signalProcess(self, signalID): if self.pid is None: raise error.ProcessExitedAlready() if signalID in ("INT", "TERM", "KILL"): win32process.TerminateProcess(self.hProcess, 1)
Example #8
Source File: tcp.py From peach with Mozilla Public License 2.0 | 5 votes |
def enumCallback(hwnd, windowName): """ Will get called by win32gui.EnumWindows, once for each top level application window. """ try: # Get window title title = win32gui.GetWindowText(hwnd) # Is this our guy? if title.find(windowName) == -1: return (threadId, processId) = win32process.GetWindowThreadProcessId(hwnd) # Send WM_CLOSE message try: win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0) win32gui.PostQuitMessage(hwnd) except: pass # Give it upto 5 sec for i in range(100): if win32process.GetExitCodeProcess(processId) != win32con.STILL_ACTIVE: # Process exited already return time.sleep(0.25) try: # Kill application win32process.TerminateProcess(processId, 0) except: pass except: pass
Example #9
Source File: _dumbwin32proc.py From python-for-android with Apache License 2.0 | 5 votes |
def signalProcess(self, signalID): if self.pid is None: raise error.ProcessExitedAlready() if signalID in ("INT", "TERM", "KILL"): win32process.TerminateProcess(self.hProcess, 1)
Example #10
Source File: _dumbwin32proc.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def signalProcess(self, signalID): if signalID in ("INT", "TERM", "KILL"): win32process.TerminateProcess(self.hProcess, 1)
Example #11
Source File: process.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def signalProcess(self, signalID): if signalID in ("INT", "TERM", "KILL"): win32process.TerminateProcess(self.hProcess, 1)
Example #12
Source File: process.py From peach with Mozilla Public License 2.0 | 4 votes |
def callWindows(self): """ Launch program to consume file """ # Launch via spawn realArgs = ["cmd.exe", "/c", self.command] for a in self.args: realArgs.append(a) phandle = os.spawnv(os.P_NOWAIT, os.path.join(os.getenv('SystemRoot'), 'system32', 'cmd.exe'), realArgs) # Give it some time before we KILL! for i in range(int(self.waitTime / 0.25)): if win32process.GetExitCodeProcess(phandle) != win32con.STILL_ACTIVE: # Process exited already break time.sleep(0.25) try: pid = ctypes.windll.kernel32.GetProcessId(ctypes.c_ulong(phandle)) if pid > 0: for cid in self.FindChildrenOf(pid): chandle = win32api.OpenProcess(1, 0, cid) win32process.TerminateProcess(chandle, 0) try: win32api.CloseHandle(chandle) except: pass win32process.TerminateProcess(phandle, 0) try: win32api.CloseHandle(phandle) except: pass except: pass