本文整理汇总了Python中win32process.TerminateProcess方法的典型用法代码示例。如果您正苦于以下问题:Python win32process.TerminateProcess方法的具体用法?Python win32process.TerminateProcess怎么用?Python win32process.TerminateProcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32process
的用法示例。
在下文中一共展示了win32process.TerminateProcess方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: closeApp
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import TerminateProcess [as 别名]
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
示例2: kill
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import TerminateProcess [as 别名]
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
示例3: signalProcess
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import TerminateProcess [as 别名]
def signalProcess(self, signalID):
if self.pid is None:
raise error.ProcessExitedAlready()
if signalID in ("INT", "TERM", "KILL"):
win32process.TerminateProcess(self.hProcess, 1)
示例4: terminate
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import TerminateProcess [as 别名]
def terminate(self):
win32process.TerminateProcess(self._handle, 1)
示例5: kill
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import TerminateProcess [as 别名]
def kill(self):
handle = win32api.OpenProcess(
win32con.PROCESS_VM_READ | win32con.PROCESS_TERMINATE, pywintypes.FALSE, self.childpid)
win32process.TerminateProcess(handle, 3)
示例6: enumCallback
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import TerminateProcess [as 别名]
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
示例7: signalProcess
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import TerminateProcess [as 别名]
def signalProcess(self, signalID):
if signalID in ("INT", "TERM", "KILL"):
win32process.TerminateProcess(self.hProcess, 1)
示例8: callWindows
# 需要导入模块: import win32process [as 别名]
# 或者: from win32process import TerminateProcess [as 别名]
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