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.
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.