How to kill a process within windows BATch file

This article is result of a friend's query related to "How to kill a windows/DOS process within a windows Batch file.

This is the solution in brief:

START "do something window" dir
FOR /F "tokens=2" %I in ('TASKLIST /NH /FI "WINDOWTITLE eq do something window"' ) DO SET PID=%I
ECHO %PID%
TASKKILL /PID %PID%

FOR Loop is only required if there are multiple processes.

A link is what I am going to provide as for more information:

Click here to access the solution

1 comment :

  1. HI sir,
    I tried executing ur script. Its telling me the following error.

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\vkaush>cd\



    C:\>FOR /F "tokens=2" %I in ('TASKLIST /NH /FI "WINDOWTITLE eq do something wind
    ow"' ) DO SET PID=%I
    'TASKLIST' is not recognized as an internal or external command,
    operable program or batch file.

    ReplyDelete