in batch how do i use taskkill properly

2019-07-22 05:11发布

问题:

I need to shutdown a program (minecraft server). I think taskkill will do the job

@echo on
TASKKILL /F /IM Minecraft server /T
echo killed!

I asked questions before of how to auto type "stop" in the console of the server, but they didn't work. I don't want to download any extra programs. Just batch, VBScript, or Java. I would prefer batch though.

Hope I made some sense anyway thanks!

回答1:

I think you're looking for this:

@echo off
for /f "tokens=2" %%a in ('tasklist^|find /i "javaw.exe"') do (set pid=%%a)
echo %pid%
taskkill /pid %pid%
pause

This will get the PID (temporary "ID" for a proccess/task), and kill it/the source. This will take a random "javaw.exe" though, so if you have more than one 'javaw.exe' / java proccess open at a time, it will take a random one, find its' PID and kill it. But as for my experience when running a Minecraft server you dont want to have many unnessecary programs open in the Background - so you can safely use this as long as you only run one 'javaw.exe' at a time :)

Hope this help!



回答2:

The correct Syntax for Taskkill

taskkill [/s Computer] [/u Domain\User [/p Password]]] [/fi FilterName] [/pid ProcessID]|[/im ImageName] [/f][/t]

To kill Minecraft Server

TaskKill /F /IM javaw.exe

Hope this Helps.