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?

| improve this question | | | | |
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
| improve this answer | | | | |
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.

| improve this answer | | | | |
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.

| improve this answer | | | | |
  • use a backtick (same key as the tilde on most U.S. layout keyboards) - not the single quote. Try that. – Goyuix Dec 15 '09 at 21:21
0

yep. simple. backquote, not single quote.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.