How to kill a single process on multiple workstati

2019-08-17 18:10发布

问题:

I'm trying to write a .bat file that can look at clients that are in a file (hosts.txt) and see if calculator is running and kill it or them but it keeps say there are not instances found.

@echo off
cd \
for /F "tokens=1-2" %%a in ("hosts.txt") do (
wmic /node:%%a process where name='Calculator.exe' call terminate
)

What would be a better way of doing this or what am I missing?

回答1:

My comment as an answer, (one line only):

@WMIC /Node:@hosts.txt Process Where "Name='calc.exe'" Call Terminate

The answer assumes you have privileges to do so, you may need to include /user:privilegedusername and /password:privilegeduserpassword.