返回列表 发帖

Python3管理Windows的软件进程

在命令行程序里打开“任务管理器”:
taskmgr
图片1.png


查看微信的进程名称:(看 映像名称
图片2.png
备注:假如微信关闭了,其进程也就消失了。



######

检测微信是否在运行中的脚本:

#coding=utf-8
import os

process_1 = len(os.popen('tasklist | findstr WeChat.exe').readlines())
print(process_1)

if process_1 >= 1 :
        print('微信正在运行中')
else:
        print('微信关闭了')


运行脚本的效果:(微信正在运行时)
图片3.png


运行脚本的效果:(微信没有运行时)
图片4.png





######

关闭微信的脚本:

#coding=utf-8
import os

command_1 = 'taskkill /F /IM WeChat.exe'
os.system(command_1)


运行脚本的效果:(关闭成功时)
图片5.png


运行脚本的效果:(关闭失败时)
图片6.png





######

启动微信的脚本:

#coding=utf-8
import os

command_1 = 'start "process" "C:\Program Files\Tencent\WeChat\WeChat.exe"'
os.system(command_1)
               

运行脚本的效果:(启动成功时)
图片7.png


运行脚本的效果:(启动失败时)
图片8.png





相关文章:
Python3调用Windows命令
Python3管理Linux的软件进程

返回列表