import psutil
import os
def printPids():
pids = psutil.pids()
for pid in pids:
try:
p = psutil.Process(pid)
print('pid=%s,pname=%s' % (pid, p.name()))
# 关闭excel进程
if p.name() == 'EXCEL.EXE':
cmd = 'taskkill /F /IM EXCEL.EXE'
os.system(cmd)
except Exception as e:
print(e)
if __name__ == '__main__':
printPids()