检测进程是否存在,并做出预定动作。
http://www.cn-dos.net/forum/viewthread.php?tid=38018
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进程,有则自动结束
http://www.cn-dos.net/forum/viewthread.php?tid=37918
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。
http://www.cn-dos.net/forum/viewthread.php?tid=22267
@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进程
http://www.cn-dos.net/forum/viewthread.php?tid=36526
检测explorer.exe进程,发现有这个进程就退出,没有就从E盘复制一个到系统目录,再运行。
我系统经常进不去,发现就是被病毒发explorer.exe文件删了。
tasklist|find /i "explorer.exe"||copy /y e:\drivers\explorer.exe %systemroot%\&&start /b explorer.exe
每30秒检测一个进程的运行,如果不存在电脑重启。
http://www.cn-dos.net/forum/viewthread.php?tid=31759
@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
检测系统的一个进程是否存在的脚本, 如果不存在,就自动关机.
http://www.cn-dos.net/forum/viewthread.php?tid=22861
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))
if errorlevel 0 ((goto start))
:end
shutdown -s -t 50
这样一来 如果Explorer.exe 进程,存在, 就是死循环.
直到 Explorer.exe 进程结束, 就执行 关机命令.
但这样有个缺点 CPU 100%
检测多个特定进程
http://www.cn-dos.net/forum/viewthread.php?tid=27743
我想实现这样一个功能:用tasklist列出当前进程清单,然后用find来搜索进程中是否含有1.exe,2.exe,3.exe......(假设啊)如果清单中含有其中一个就执行某个操作。我想用FOR来实现循环可是怎么试也不行啊!!我是这样试的:
tasklist | for %%j in (1.exe,2.exe,3.exe) do find "%%j" && goto :p
find是不是不能用for啊?请高人指点。
---------
tasklist | findstr "1.exe 2.exe 3.exe"&&goto :p
for不会接受传递自tasklist的数据,它是打in来定义的
---------
@echo off
set 1.exe=被定义的程序
set 2.exe=被定义的程序
set 3.exe=被定义的程序
for /f "tokens=1" %%i in ('tasklist /NH') do (
if defined %%i echo %%i
)
pause>nul
---------
检测和退出进程问题
http://www.cn-dos.net/forum/viewthread.php?tid=25357
A B 两进程存在,若A不存在,则退出B。每隔N秒循环检测一次,退出B后,退出程序
tasklist|findstr /i "A.exe" ||(taskkill /im B.exe /t /f&exit)
列出当前运行的进程,可自定义说明内容,手动关闭进程。
可改良后自动判断处理进程。http://www.cn-dos.net/forum/viewthread.php?tid=27405
@echo off
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\HPQ\IAM\bin
title 进程分析自定义结束进程程序
echo 按任意键开始分析
pause>nul
set space=
echo.
echo 程序分析如下:
echo =========================================================================
echo.
echo 进程名称 进程说明
echo.
call tasklist.exe
::以下定义程序说明,自己可以补充。
set System=『系统进程』
set smss.exe=『系统进程』调用对话管理子系统和负责操作你系统的对话
set csrss.exe=『系统进程』管理Windows图形相关任务
set winlogon.exe=『系统进程』
set services.exe=『系统进程』管理启动和停止服务
set lsass.exe=『系统进程』用于本地安全和登陆策略
set svchost.exe=『系统进程』用来运行动态链接库dll文件
set ctfmon.exe=·提供语音识别、手写识别等
set conime.exe=·输入法编辑器相关程序
::主程序
setlocal enabledelayedexpansion
for /f "tokens=1" %%i in ('tasklist /NH') do (
set str=%%i %space%
set str=!str:~0,20!
if defined %%i (echo !str! !%%i!) else echo !str! ‖根据进程自已输进程名)
echo =========================================================================
echo 分析完毕...
:goto title
title 结束进程
set /p run=请输入要结束的程序名
::ntsd -c q -pn %run%
taskkill /f /t /im %run%
pause>nul 先分析PID和进程。然后自定义结束
http://www.loverat.cn/topic.asp?TOPIC_ID=1211
Detect if a process exists and take a predefined action.
http://www.cn-dos.net/forum/viewthread.php?tid=38018
tasklist /nh>d:\tddown~1\1.txt
find /i "QQ.exe" d:\tddown~1\1.txt
if ERRORLEVEL 1 (echo qq.exe does not exist) else (echo qq.ex exists)
------------Second-----------
tasklist /nh|find /i "QQa.exe"
if ERRORLEVEL 1 (echo qqa.exe does not exist) else (echo qqa.exe exists)
Check if there is a QQ.EXE process on the computer, and if so, automatically end it
http://www.cn-dos.net/forum/viewthread.php?tid=37918
a) First, use tasklist to input the process list to find, let find find the qq.exe process. If found, then perform the following end operation; if not found, exit the bat
@echo off
tasklist|find /i "qq.exe" ||exit
taskkill /im qq.exe /f
b) Put the process list in document A and then use the FIND search code:
@echo off
tasklist>C:\a.txt
find "QQ.exe" C:\a.txt&&taskkill /f /im "QQ.exe"
c) If it is not a cyclic monitoring, directly taskkill... Anyway, the final purpose is to not have the QQ process.
Automatically detect the process list every 20 seconds and automatically close notepad.exe.
http://www.cn-dos.net/forum/viewthread.php?tid=22267
@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
Detect explorer.exe process
http://www.cn-dos.net/forum/viewthread.php?tid=36526
Detect the explorer.exe process. If this process is found, exit; if not, copy one from the E drive to the system directory and then run it.
My system often can't enter, and I find that the explorer.exe file is deleted by the virus.
tasklist|find /i "explorer.exe"||copy /y e:\drivers\explorer.exe %systemroot%\&&start /b explorer.exe
Detect the running of a process every 30 seconds, and if it does not exist, restart the computer.
http://www.cn-dos.net/forum/viewthread.php?tid=31759
@echo off
rem Restart should use -r
tasklist|findstr /i "explorer.exe" ||shutdown -r -t 50
rem Bamboo said that the first message of ping does not need to wait, so the delay of 30 seconds should use -n 31
ping 127.1 -n 31 >nul 2>nul
rem No need to use a loop, just call yourself
call %0
Script to detect whether a process of the system exists. If it does not exist, automatically shut down.
http://www.cn-dos.net/forum/viewthread.php?tid=22861
tasklist >tasklist.txt
rem Process name such as smss.exe
find /i tasklist.txt "process name"
if errorlevel 1 ((del /q tasklist.txt)&(goto end))
if errorlevel 0 ((del /q tasklist.txt)&(echo There is the process you want)&pause&exit)
:end
shutdown -s -t 1
But this only detects once when this bat runs, not real-time monitoring
Use Goto statement to do monitoring
:start
tasklist >tasklist.txt
find /i tasklist.txt "Explorer.exe"
if errorlevel 1 ((del /q tasklist.txt)&(goto end))
if errorlevel 0 ((goto start))
:end
shutdown -s -t 50
In this way, if the Explorer.exe process exists, it is an infinite loop.
Until the Explorer.exe process ends, the shutdown command is executed.
But this has a disadvantage of 100% CPU
Detect multiple specific processes
http://www.cn-dos.net/forum/viewthread.php?tid=27743
I want to implement such a function: list the current process list with tasklist, then use find to search whether the process contains 1.exe, 2.exe, 3.exe... (assuming). If one of them is in the list, perform a certain operation. I want to use FOR to implement the loop but can't get it to work. This is how I tried:
tasklist | for %%j in (1.exe,2.exe,3.exe) do find "%%j" && goto :p
Can't find use for? Please give pointers.
---------
tasklist | findstr "1.exe 2.exe 3.exe"&&goto :p
for will not accept the data passed from tasklist, it is defined by in
---------
@echo off
set 1.exe=defined program
set 2.exe=defined program
set 3.exe=defined program
for /f "tokens=1" %%i in ('tasklist /NH') do (
if defined %%i echo %%i
)
pause>nul
---------
Detection and exit process problem
http://www.cn-dos.net/forum/viewthread.php?tid=25357
Processes A and B exist. If A does not exist, exit B. Detect every N seconds in a loop. After exiting B, exit the program
tasklist|findstr /i "A.exe" ||(taskkill /im B.exe /t /f&exit)
List the currently running processes, can customize the description content, manually close the process.
Can be improved to automatically judge and process the process.http://www.cn-dos.net/forum/viewthread.php?tid=27405
@echo off
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\HPQ\IAM\bin
title Process analysis custom end process program
echo Press any key to start analysis
pause>nul
set space=
echo.
echo Program analysis is as follows:
echo =========================================================================
echo.
echo Process name Process description
echo.
call tasklist.exe
::The following defines the program description, you can supplement it yourself.
set System=『System process』
set smss.exe=『System process』Call the dialogue management subsystem and be responsible for operating the dialogue of your system
set csrss.exe=『System process』Manage Windows graphics-related tasks
set winlogon.exe=『System process』
set services.exe=『System process』Manage start and stop services
set lsass.exe=『System process』Used for local security and login policy
set svchost.exe=『System process』Used to run dynamic link library dll files
set ctfmon.exe=·Provide speech recognition, handwriting recognition, etc
set conime.exe=·Input method editor related program
::Main program
setlocal enabledelayedexpansion
for /f "tokens=1" %%i in ('tasklist /NH') do (
set str=%%i %space%
set str=!str:~0,20!
if defined %%i (echo !str! !%%i!) else echo !str! ‖Enter the process name according to the process yourself)
echo =========================================================================
echo Analysis is complete...
:goto title
title End process
set /p run=Please enter the program name to end
::ntsd -c q -pn %run%
taskkill /f /t /im %run%
pause>nul First analyze PID and process. Then customize the end
http://www.loverat.cn/topic.asp?TOPIC_ID=1211