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-02 19:09
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch script to close a process View 2,478 Replies 5
Original Poster Posted 2006-12-15 10:42 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 201
Posts 69
Joined 2005-12-07 17:35
20-year member
UID 46678
Gender Male
Status Offline
For example, I use tasklist>1.txt, and then I need to find the process with PID 132 in this 1.txt, and then use taskkill /pid to close this process. How to write the batch script?
Mainly I don't know how to find things in 1.txt with batch. Please forgive me.
Can the experts teach me?

[ Last edited by namejm on 2006-12-14 at 10:42 PM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
namejm -2 2006-12-15 10:46
Floor 2 Posted 2006-12-15 10:53 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Terminate the process with the specified PID. You don't need to first use tasklist and then terminate it; you can directly use taskkill /pid. The demonstration code is as follows:

@echo off
taskkill /pid 132>nul 2>nul&& echo The process with PID 132 has been terminated||echo The process with PID 132 does not exist
pause
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-12-15 11:30 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 201
Posts 69
Joined 2005-12-07 17:35
20-year member
UID 46678
Gender Male
Status Offline
Thanks, and another question. How to write a batch script to close the process with PID 132. The requirement is that once the user runs the program with PID 132, it will be automatically closed after 5 seconds
Floor 4 Posted 2006-12-15 11:30 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 201
Posts 69
Joined 2005-12-07 17:35
20-year member
UID 46678
Gender Male
Status Offline
Then how to change the title?
Floor 5 Posted 2006-12-15 12:56 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Originally posted by sjs0512 at 2006-12-15 11:30:
Thanks. Another question. How to write a batch script to close the process with PID 132.
Requirement: Once the user runs the program with PID 132, it will be automatically closed after 5 seconds


  Generally, this method is not recommended. This requires the batch script to always monitor the system processes, which will result in relatively high CPU usage.
Floor 6 Posted 2006-12-15 20:51 ·  中国 辽宁 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
You can use VBS to monitor a certain process, and if it is running, kill it. But it needs to be resident in memory.
Forum Jump: