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)

 

你可能感兴趣的:(python检测进程是否存在)