0
点赞
收藏
分享

微信扫一扫

【python代码块】通过进程名批量结束同名进程

boom莎卡拉卡 2022-01-14 阅读 48
def taskkillbyname(killname):
    preq=os.popen('tasklist /fi "imagename eq {}"'.format(killname))
    pidlist=[]
    for p in preq:
        plist=p.split(" ")
        for pl in plist:
            if pl.isnumeric() and pl is not killname:
                pidlist.append(pl)
                break
        # print(p,end="")
    # os.system('chcp 65001')
    for pid in pidlist:
        preq=os.popen("taskkill /f /pid {}".format(pid))
taskkillbyname("chrome.exe")
举报

相关推荐

0 条评论