Python win32api 模块,TerminateProcess() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用win32api.TerminateProcess()

项目:code    作者:ActiveState    | 项目源码 | 文件源码
def subprocess_terminate( proc ) :
    try:
        proc.terminate()
    except AttributeError:
        print " no terminate method to Popen.."
        try:
            import signal
            os.kill( proc.pid , signal.SIGTERM)
        except AttributeError:
            print "  no os.kill, using win32api.."
            try:
                import win32api
                PROCESS_TERMINATE = 1
                handle = win32api.OpenProcess( PROCESS_TERMINATE, False, proc.pid)
                win32api.TerminateProcess(handle,-1)
                win32api.CloseHandle(handle)
            except ImportError:
                print "  ERROR: could not terminate process."
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def ms_win_kill(pid):
    import win32api
    handle = win32api.OpenProcess(1, 0, pid)
    return (0 != win32api.TerminateProcess(handle, 0))
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def killProcName(procname):
    # Change suggested by Dan Knierim, who found that this performed a
    # "refresh", allowing us to kill processes created since this was run
    # for the first time.
    try:
        win32pdhutil.GetPerformanceAttributes('Process','ID Process',procname)
    except:
        pass

    pids = win32pdhutil.FindPerformanceAttributesByName(procname)

    # If _my_ pid in there, remove it!
    try:
        pids.remove(win32api.GetCurrentProcessId())
    except ValueError:
        pass

    if len(pids)==0:
        result = "Can't find %s" % procname
    elif len(pids)>1:
        result = "Found too many %s's - pids=`%s`" % (procname,pids)
    else:
        handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0,pids[0])
        win32api.TerminateProcess(handle,0)
        win32api.CloseHandle(handle)
        result = ""

    return result
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def killProcName(procname):
    # Change suggested by Dan Knierim, who found that this performed a
    # "refresh", allowing us to kill processes created since this was run
    # for the first time.
    try:
        win32pdhutil.GetPerformanceAttributes('Process','ID Process',procname)
    except:
        pass

    pids = win32pdhutil.FindPerformanceAttributesByName(procname)

    # If _my_ pid in there, remove it!
    try:
        pids.remove(win32api.GetCurrentProcessId())
    except ValueError:
        pass

    if len(pids)==0:
        result = "Can't find %s" % procname
    elif len(pids)>1:
        result = "Found too many %s's - pids=`%s`" % (procname,pids)
    else:
        handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0,pids[0])
        win32api.TerminateProcess(handle,0)
        win32api.CloseHandle(handle)
        result = ""

    return result
项目:w4py    作者:Cito    | 项目源码 | 文件源码
def killPID(pid, sig=None):
        """Kill the process with the given pid."""
        try:
            if sig is None:
                from signal import SIGTERM
                sig = SIGTERM
            os.kill(pid, sig)
        except (AttributeError, ImportError):
            if win32api:
                handle = win32api.OpenProcess(1, False, pid)
                win32api.TerminateProcess(handle, -1)
                win32api.CloseHandle(handle)