python怎么判断进程是否杀掉?
发布时间:2026-02-02 21:52:50

在python中,可以通过判断过程是否存在来判断过程是否被杀死:
win32com库可用于python中获取进程信息。
importwin32comm.client
defcheck_exsit(process_name):
WMI=win32com.client.GetObject('winmgmts:')
processCodeCov=WMI.ExecQuery('select*Win32fromProcesswhereNamelike"%{}%"'.format(process_name))
iflen(processCodeCov)>0:
returnTrue
else:
returnFalse
if__name__='__main__':
res=check_exsit('tray.exe')
print(res)请关注Python自学网了解更多Python知识。
