python检测进程是否存在

 

import win32com.client

def check_exsit(process_name):
    WMI = win32com.client.GetObject('winmgmts:')
    processCodeCov = WMI.ExecQuery('select * from Win32_Process where Name like "%{}%"'.format(process_name))
    if len(processCodeCov) > 0:
        return True
    else:
        return False

if __name__ == '__main__':
    res = check_exsit('tray.exe')
    print(res)

 

posted @ 2019-08-23 17:35  JaryTom  阅读(4498)  评论(0编辑  收藏  举报