The method of judging whether a process exists in DOS

Time:2020-1-13

Detect whether the process exists, and make a predetermined action.

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 error level 1 (echo qqa.exe does not exist) else (echo qqa.exe exists)

Check whether there is qq.exe process in the computer, and if there is, it will automatically end

a) First, use tasklist to input the process list to find, and let find find the qq.exe process. If it is found, perform the following end operation, and exit bat if it is not found

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

b) . put the process list in a document and then find the code:

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

c) . if it is not for cyclic monitoring, directly take a task kill… Anyway, the ultimate goal is not to have QQ process.

Check the process list automatically every 20 seconds, and close notepad.exe automatically.

@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

Check the explorer.exe process, and if there is one, exit. If not, copy one from disk e to the system directory and run it again.
My system is often unable to enter. I found that it was deleted by the explorer.exe file sent by the virus.

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

Check the running of a process every 30 seconds, if there is no computer restart.

@echo off
REM reboot should use – R
tasklist|findstr /i “explorer.exe” ||shutdown -r -t 50
REM will sort mottled bamboo said that the first message of Ping does not need to wait, so it should be delayed by 30 seconds and – N 31 should be used
ping 127.1 -n 31 >nul 2>nul
REM you don’t need to use the loop, just call yourself
call %0

A script that detects whether a process of the system exists. If it does not, it will shut down automatically

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 has the process you want) & pause & exit)
:end
shutdown -s -t 1

But in this way, only this bat can be tested once, without real-time monitoring

Monitor with goto statement

: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 a dead cycle
The shutdown command is executed until the explorer.exe process ends
But there is a disadvantage: CPU 100%


Detect multiple specific processes

I want to realize such a function: use tasklist to list the current process list, and then use find to search whether there is 1.exe, 2.exe, 3.exe in the process… (suppose) if there is one in the list, perform an operation. I want to use for to realize circulation, but I can’t even try!! I tried this:
tasklist | for %%j in (1.exe,2.exe,3.exe) do find “%%j” && goto :p
Can’t find use for? Please advise me.
———
tasklist | findstr “1.exe 2.exe 3.exe”&&goto :p
For does not accept data passed from tasklist, it is defined by typing
———
@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
———

Detect and exit process problems

A and B processes exist. If a does not exist, exit B. Cycle detection every N seconds, exit b, exit the program

tasklist|findstr /i “A.exe” ||(taskkill /im B.exe /t /f&exit)

List the currently running processes. You can customize the description and manually close the processes.
It can automatically judge the processing process after improvement.
 

@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.
The echo program is analyzed as follows:
echo =========================================================================
echo.
Echo process name process description
echo.
call tasklist.exe

:: the following definition program description can be supplemented by yourself.
Set system = system process
Set smss.exe = system process calls the dialogue management subsystem and is responsible for the dialogue of your system
Set csrss.exe = system process to manage windows graphics related tasks
Set winlogon.exe = system process
Set services.exe = system process management start and stop services
Set lsass.exe = system process is used for local security and login policy
Set svchost.exe = system process is used to run DLL file of dynamic link library
Set ctfmon.exe = · provide speech recognition, handwriting recognition, etc
Set conime.exe = · input method editor related programs

:: 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 itself)
echo =========================================================================
Echo analysis finished
: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%
First, analyze PID and process. And then customization ends

——————————————————————————–

To display the pipeline (|) or redirection character (< or >) when using the echo command, use the caret (^) before the pipeline (|) or redirection character (for example, ^ >, ^ < or ^). If you need to use a caret (^), type two carets (^ ^).

||

Usage:
First order, second order [, third order…]

In this way, multiple commands can be executed at the same time. When the correct command is executed, the subsequent commands will not be executed. If the correct command does not appear, all commands will be executed all the time;

Sample:

D:\TDDownload>dir *.txt||ren 1.txt 3.txt&&dir *.txt
The volume in drive d is application
The serial number of the volume is b445-f155

D: Directory for \ tddownload

2008-01-26 15:35 229 1.txt
2008-01-26 15:35 229 2.txt
2008-01-26 15:35 229 third eye.txt
3 files 687 bytes
0 directory 7510728704 free bytes

D:\TDDownload>dir 3.txt||ren 1.txt 3.txt&&dir *.txt
The volume in drive d is application
The serial number of the volume is b445-f155

D: Directory for \ tddownload

cannot find file
The volume in drive d is application
The serial number of the volume is b445-f155

D: Directory for \ tddownload

2008-01-26 15:35 229 2.txt
2008-01-26 15:35 229 3.txt
2008-01-26 15:35 229 third eye.txt
3 files 687 bytes
0 directory 7510728704 free bytes

D:\TDDownload>