杀死TASKKILL只有一个进程 [英] Kill only one process with taskkill

查看:537
本文介绍了杀死TASKKILL只有一个进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于运行游戏,我需要两次启动它的exe文件,然后杀死RUNDLL32.EXE进程之一的目的。我不想用手工每次都这样做,所以我把它放在一个批处理文件,像这样:

For the purpose of running a game I need to start its exe twice and then kill one of the rundll32.exe processes. I don't want to do this by hand every time so I put it in a batch file like so:

start Gothic2.exe
start Gothic2.exe
taskkill /IM rundll32.exe /F

有RUNDLL32.EXE运行两个实例无一不被杀害,我只需要终止其中之一。 PID的不帮助的,因为RUNDLL32.EXE得到一个新的每次启动的时间。
我怎么能杀死只有一个进程的时候有更多的具有相同的名称?

There are 2 instances of rundll32.exe running and both are killed, I only need to terminate one of them. PIDs don't help because the rundll32.exe gets a new one every time it is started. How can I kill only one process when there are more with the same name?

推荐答案

假设RUNDLL32.EXE旋转起来,当你开始Gothic2.exe并有系统上运行的其他进程,这也将是旋转起来,它是OK杀RUNDLL32.EXE的第一个实例,你可以使用这样的:

Assuming that rundll32.exe spins up when you start Gothic2.exe AND that there are no other processes running on your system that would also spin that up AND that it's OK to kill the first instance of rundll32.exe, you could use this:

start Gothic2.exe
for /f "tokens=2" %%x in ('tasklist ^| findstr rundll32.exe') do set PIDTOKILL=%%x
start Gothic2.exe
taskkill /F /PID %PIDTOKILL%

我想,如果你想杀死RUNDLL32.EXE的第二个实例,而不是,你可以修改它是这样的:

I suppose if you wanted to kill the second instance of rundll32.exe instead, you could modify it like this:

start Gothic2.exe
for /f "tokens=2" %%x in ('tasklist ^| findstr rundll32.exe') do set PIDTOSAVE=%%x
start Gothic2.exe
for /f "tokens=2" %%x in ('tasklist ^| findstr rundll32.exe ^| findstr /v %PIDTOSAVE%') do taskkill /F /PID %%x

这篇关于杀死TASKKILL只有一个进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆