A method of determining whether a process exists in DOS

Source: Internet
Author: User
Tags exit echo command goto

Detects if a process exists and makes a predetermined action.


find/i "QQ.exe" D:tddown~11.txt

if errorlevel 1 (echo Qq.exe does not exist) else (echo Qq.ex exists)

------------a second-----------

tasklist/nh|find/i "QQa.exe"

if errorlevel 1 (echo Qqa.exe does not exist) else (echo Qqa.exe exists)

Check if there are any QQ.EXE processes in the computer, then automatically end

A), first with the tasklist input process list to find, let finds identify qq.exe process, if found, then perform the following end operation, can not find the exit bat

@echo off

tasklist|find/i "Qq.exe" | | Exit

Taskkill/im qq.exe/f

b), place the list of processes in a document and then find the code using found:

@echo off


Find "QQ.exe" c:a.txt&&taskkill/f/im "QQ.exe"

c), if not to cycle monitoring, direct taskkill ... Anyway, the ultimate goal is not to have the QQ process.

Automatically notepad.exe the process list every 20 seconds.

@echo off

: 1

tasklist | Find "notepad.exe" >>c:notepad.luowei

If exist C:notepad.luowei taskkill/f/im notepad.exe

Ping 127.1-n >nul 2>nul

Goto 1

Detecting Explorer.exe processes

Detects the Explorer.exe process, discovers this process to exit, does not copy one to the system directory from the e disk, then runs.

My system often can't go in, found that is the virus sent Explorer.exe file deleted.

tasklist|find/i "Explorer.exe" | | copy/y E:driversexplorer.exe%systemroot%&&start/b Explorer.exe

Detects the operation of a process every 30 seconds if there is no computer reboot.

@echo off

REM reboot should use-r

tasklist|findstr/i "Explorer.exe" | | Shutdown-r-T 50

REM Willsort The owner said, Ping's first message is not to wait, so 30 seconds delay, should use-n 31

Ping 127.1-n >nul 2>nul

REM does not have to use loops, call yourself on the line


A script that detects whether a process exists in the system, and shuts down automatically if it does not exist.

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 this is the only bat. Run one Test at a time without real-time monitoring

Monitoring 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

So if the Explorer.exe process exists, it is a dead loop.

The shutdown command is executed until the Explorer.exe process finishes.

But this has a disadvantage CPU 100%

Detecting multiple specific processes//www.45it.com

I want to implement a feature that lists the current process list with tasklist, and then uses find to search for 1.exe,2.exe,3.exe in the process ... If one of the listings contains one, perform an action. I would like to use for to achieve the loop but how to try it is not AH!! That's what I'm trying to do:

tasklist | For%%j in (1.exe,2.exe,3.exe) does find "%%j" && Goto:p

Find is not used for Ah, please expert advice.


tasklist | Findstr "1.exe 2.exe 3.exe" &&goto:p

For does not accept data that is passed from tasklist, it is defined in


@echo off

Set 1.exe= the defined program

Set 2.exe= the defined program

Set 3.exe= the defined program

for/f "Tokens=1"%%i in (' Tasklist/nh ') does (

If defined%%i echo%%i




Detect and exit process issues

A B Two processes exist, if a does not exist, then exit B. Check every n seconds, exit B, exit the program

tasklist|findstr/i "A.exe" | | (Taskkill/im b.exe/t/f&exit)

Lists the currently running processes, can customize the description, and manually close the process.

Can be modified to automatically judge the processing process.

@echo off

Path=c:windowssystem32; C:windows; C:windowssystem32wbem; C:Program Fileshpqiambin

Title Process profiling custom End Process Program

echo presses any key to start analysis


Set space=


The Echo program is analyzed as follows:

Echo =========================================================================


Echo Process Name Process description


Call Tasklist.exe

:: The following definition of the program description, you can add.

Set system= "System process"

Set smss.exe= "System process" calls the dialog management subsystem and the conversation that is responsible for manipulating your system

Set csrss.exe= "System processes" manage Windows graphics-related tasks

Set winlogon.exe= "System process"

Set services.exe= "System processes" manage start and stop services

Set lsass.exe= "System processes" for local security and login policies

Set svchost.exe= "System processes" to run dynamic-link library DLL files

Set ctfmon.exe= provides 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 ') does (

Set str=%%i%space%

Set str=!str:~0,20!

If defined%%i (echo!str!!%%i!) Else echo!str! ‖ per process Self-lost process name)

Echo =========================================================================

Echo Analysis finished ...

: Goto Title

Title End Process

set/p run= Please enter the name of the program you want to end

:: Ntsd-c q-pn%run%


Pause>nul first analyze the PID and process. And then customize the end


To display a pipe (|) or redirection character (< or >) when using the Echo command, in the pipe (|) or redirect character (such as,^>, ^<, or ^|) Use the caret (^) in front of the If you need to use a caret (^), type two characters (^^).



First Command | | The second command [| | | The Third order ...]

In this way, you can execute multiple commands at the same time, do not execute the following commands after encountering the correct command, and execute all commands if the correct command is not present;


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:tddownload's Directory

2008-01-26 15:35 229 1.txt

2008-01-26 15:35 229 2.txt

2008-01-26 15:35 229 first three eyes. txt

3 Files 687 bytes

0 Directory 7,510,728,704 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:tddownload's Directory

File not found

The volume in drive D is application

The serial number of the volume is b445-f155

D:tddownload's Directory

2008-01-26 15:35 229 2.txt

2008-01-26 15:35 229 3.txt

2008-01-26 15:35 229 first three eyes. txt

3 Files 687 bytes

0 Directory 7,510,728,704 Free bytes


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: