3

Windows scripting noob here. Say I've got the name of a .dll I need to delete or copy over, and I'm getting the classic "The file is in use by another process..." error. I know I can run tasklist with the /m switch and pass it the dll name. Then I can get the PID for the processes and kill them with taskkill.

How can I do this in one step in a batch file?

4 Answers 4

4

Reminder: in a batch file you will need to use the double "%%" instead a single

FOR /F "usebackq tokens=2 skip=2" %i IN (`tasklist /m winsta.dll`) DO taskkill /PID %i
1
1

FOR /F "usebackq tokens=2 skip=2" %%i IN (TASKLIST /FI "IMAGENAME eq tomcat6.exe") DO taskkill /F /PID %%i

will automatically kill the tomcat process.

0

Goyuix,

I can't seem to get the tasklist results to parse. FOR /F "usebackq tokens=2 skip=2" %i IN ('tasklist /m winsta.dll') DO echo %i The tasklist command by itself is fine, but the loop is not recognizing the tasklist resuls. Rather it appears to be parsing the string. I can output the task list results to file and parse with the loop, but I thought I might be missing something simple.

1
  • use a backtick (same key as the tilde on most U.S. layout keyboards) - not the single quote. Try that.
    – Goyuix
    Dec 15, 2009 at 21:21
0

yep. simple. backquote, not single quote.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .