Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FOR loop troubles

Status
Not open for further replies.

tobjob

IS-IT--Management
Sep 17, 2009
10
US
I am trying to take the PID output of the tasklist command and send it to the taskkill command. I have successfully createed a FOR loop to go through the values of the tasklist command and echo out the PID of the process. Mstsc.exe is used as just an example process to kill.

for /F "tokens=2 skip=3" %%A in ('tasklist /FI "IMAGENAME eq mstsc.exe"') do echo %%A

The issue is when I try to add the taskkill command to the do portion of the for loop.

for /F "tokens=2 skip=3" %%A in ('tasklist /FI "IMAGENAME eq mstsc.exe"') do taskill /F /PID %%A.

When I execute the for loop in a batch file it does not recognize the taskkill command. Any help would be appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top