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-01 13:51
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Closed: Batch script for checking and closing processes View 1,739 Replies 4
Original Poster Posted 2005-11-20 16:51 ·  中国 福建 泉州 电信
初级用户
Credits 51
Posts 14
Joined 2005-11-06 20:02
20-year member
UID 44706
Gender Male
Status Offline
I want to write a line in a batch script to check if there is a specified program in the process. If there is, use GOTO to close another specified program. If not, use GOTO to execute other commands.

Thank you, brother. I know how to use TASKLIST to check, but I want to compile a program. For example, if Photoshop.exe is detected in the process, in the batch script, use the GOTO command to close another specified program TheWorld.exe. If Photoshop.exe is not detected, use GOTO to execute other program commands.

[ Last edited by willsort on 2005-11-25 at 19:34 ]
Floor 2 Posted 2005-11-20 17:15 ·  中国 广东 广州 白云区 电信
荣誉版主
★★★
Credits 718
Posts 313
Joined 2005-09-26 00:00
20-year member
UID 42844
Gender Male
Status Offline
You can use tasklist to view WIN processes.
Floor 3 Posted 2005-11-20 23:14 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
Try this!

tasklist |findstr /i "Photoshop.exe" &&taskkill /fi "imagename eq TheWorld.exe" ||echo No Photoshop is running
Floor 4 Posted 2005-11-20 23:25 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
In my place, when intercepting the output of tasklist with a pipe, sometimes the process is incomplete. If you also encounter such a problem, switch to the following code.

tasklist /fi "imagename eq Photoshop.exe"|findstr /i "Photoshop.exe" &&taskkill /fi "imagename eq TheWorld.exe" ||echo No Photoshop is running
Floor 5 Posted 2005-11-20 23:37 ·  中国 福建 泉州 电信
初级用户
Credits 51
Posts 14
Joined 2005-11-06 20:02
20-year member
UID 44706
Gender Male
Status Offline
Thanks, Brother Wunaike. I'm really grateful. I looked at it for a while. Finally understood this command. Really appreciate you.

[ Last edited by zreo on 2005-11-20 at 23:44 ]
Forum Jump: