China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 03:22
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Organize] Batch processing to detect whether a process exists and take a predetermined action. View 3,106 Replies 13
Original Poster Posted 2008-02-29 15:15 ·  中国 浙江 温州 电信
初级用户
★★
Credits 170
Posts 83
Joined 2007-11-30 16:44
18-year member
UID 104263
Gender Male
Status Offline
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
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
lxmxn +8 2008-02-29 18:48
moniuming +2 2008-03-01 21:00
kyqm +2 2009-11-18 21:10
Floor 2 Posted 2008-03-01 02:47 ·  中国 浙江 杭州 电信
初级用户
九州散人
Credits 55
Posts 28
Joined 2007-09-14 07:49
18-year member
UID 97342
Gender Male
Status Offline
Floor 3 Posted 2008-03-01 19:19 ·  中国 河北 邯郸 联通
新手上路
Credits 7
Posts 4
Joined 2006-05-03 13:01
20-year member
UID 54876
Status Offline
Learned something, thanks.
Floor 4 Posted 2008-03-01 20:57 ·  中国 广西 百色 中移铁通
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Good stuff, but, really don't want people with bad intentions to see this post
Floor 5 Posted 2008-03-02 02:34 ·  中国 广西 南宁 电信
新手上路
Credits 10
Posts 5
Joined 2007-06-04 19:36
19-year member
UID 90251
Gender Male
Status Offline
Newcomer reporting, come in and learn~
Floor 6 Posted 2008-03-04 17:10 ·  中国 福建 福州 联通
高级用户
★★
Credits 581
Posts 277
Joined 2006-12-23 05:10
19-year member
UID 74328
Gender Male
Status Offline
This thing is powerful, a bit scary
Floor 7 Posted 2008-03-04 22:41 ·  中国 江西 南昌 电信
中级用户
★★
Credits 245
Posts 123
Joined 2007-06-08 09:04
19-year member
UID 90636
Gender Female
Status Offline
Learning
Floor 8 Posted 2008-03-06 14:38 ·  中国 广东 珠海 电信
新手上路
Credits 4
Posts 2
Joined 2007-07-25 19:46
19-year member
UID 94029
Gender Male
Status Offline
This thing is pretty good....
Get it down and learn it slowly...
Floor 9 Posted 2008-03-06 14:59 ·  中国 辽宁 朝阳 联通
铂金会员
★★★★
痴迷DOS者
Credits 5,798
Posts 1,924
Joined 2003-06-20 00:00
23-year member
UID 5583
Gender Male
From 金獅電腦軟體工作室
Status Offline
熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
Floor 10 Posted 2009-05-27 01:29 ·  中国 浙江 杭州 电信
银牌会员
★★
三生缘里笑红尘
Credits 1,063
Posts 292
Joined 2003-03-09 00:00
23-year member
UID 1073
Gender Male
Status Offline
Floor 11 Posted 2009-05-27 13:29 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Add a little something for the thread starter:
For starting explorer.exe, it is recommended to use "start explorer.exe"
Otherwise, the batch window cannot be automatically closed
Floor 12 Posted 2009-05-27 21:41 ·  中国 山东 泰安 新泰市 联通
新手上路
Credits 16
Posts 9
Joined 2009-05-26 23:25
17-year member
UID 146033
Gender Male
Status Offline
This post is very practical, support the original poster.
Floor 13 Posted 2009-05-28 08:19 ·  中国 广东 广州 广东金万邦科技投资有限公司(新一代数据中心)IDC机房(BGP)
初级用户
Credits 68
Posts 36
Joined 2006-12-19 09:47
19-year member
UID 73948
Gender Male
Status Offline
Learning.
Floor 14 Posted 2009-06-05 01:52 ·  中国 湖南 长沙 电信
社区乞丐
Credits -31
Posts 32
Joined 2009-03-12 08:41
17-year member
UID 141109
Gender Male
Status Offline
Can't understand it, it's like天书
Forum Jump: