首页 > 编程 > BAT > 正文

DOS中判断进程是否存在的方法

2020-06-09 13:54:23
字体:
来源:转载
供稿:网友

检测进程是否存在,并做出预定动作。

tasklist /nh>d:/tddown~1/1.txt

find /i "QQ.exe" d:/tddown~1/1.txt
if ERRORLEVEL 1 (echo qq.exe不存在) else (echo qq.ex存在)
------------第二个-----------
tasklist /nh|find /i "QQa.exe"
if ERRORLEVEL 1 (echo qqa.exe不存在) else (echo qqa.exe存在)


检查电脑里有没QQ.EXE进程,有则自动结束

a)、先用tasklist 输入进程列表给find ,让find找出qq.exe进程,如果找到,那执行下面的结束操作,找不到就退出bat

@echo off
tasklist|find /i "qq.exe" ||exit
taskkill /im qq.exe /f

b)、把进程列表放在A文档里面然后再用FIND查找代码:

@echo off
tasklist>C:/a.txt
find "QQ.exe" C:/a.txt&&taskkill /f /im "QQ.exe"

c)、如果不是要循环监控的话,直接taskkill。。。反正最终目的是不要有QQ进程。


每隔20秒自动检测进程列表,自动关闭notepad.exe。

@echo off
:1
tasklist | find "notepad.exe" >>c:/notepad.luowei
if exist c:/notepad.luowei taskkill /f /im notepad.exe
ping 127.1 -n 20 >nul 2>nul
goto 1


检测explorer.exe进程

检测explorer.exe进程,发现有这个进程就退出,没有就从E盘复制一个到系统目录,再运行。
我系统经常进不去,发现就是被病毒发explorer.exe文件删了。

tasklist|find /i "explorer.exe"||copy /y e:/drivers/explorer.exe %systemroot%/&&start /b explorer.exe


每30秒检测一个进程的运行,如果不存在电脑重启。

@echo off
rem 重启应该使用-r
tasklist|findstr /i "explorer.exe" ||shutdown -r -t 50
rem willsort斑竹说过,ping的第一条消息是不需要等待的,所以延时30秒,应该用-n 31
ping 127.1 -n 31 >nul 2>nul
rem 不必使用循环,call一下自己就行了
call %0


检测系统的一个进程是否存在的脚本, 如果不存在,就自动关机.

tasklist >tasklist.txt
rem 进程名如 smss.exe
find /i tasklist.txt "进程名"
if errorlevel 1 ((del /q tasklist.txt)&(goto end))
if errorlevel 0 ((del /q tasklist.txt)&(echo 有你想要的进程)&pause&exit)
:end
shutdown -s -t 1

不过这样只有这个bat运行一次检测一次,没有实时监控

用Goto 语句做 监测

:start
tasklist >tasklist.txt
find /i tasklist.txt "Explorer.exe"
if errorlevel 1 ((del /q tasklist.txt)&(goto end))

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表