Jump to content

KIll all but last process


oztech
 Share

Recommended Posts

I have a script which kills the Microsoft Word instances running on my Windows 2003 server. The problem is it kills all the instances, where as I want to keep the last instance or last microsoft word process as it is And kill the rest of the ones.

Here is the code:

FOR /F "tokens=2" %%I IN ('tasklist ^| Find "WINWORD.EXE"') DO CALL :windowlist %%I

goto :EOF

goto :EOF

:windowlist

echo %1

TASKKILL /PID %1 /T

goto :EOF

How can I achieve this.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy