title: How to find exact match using PSLIST and FIND in Batch/CMD
body: <p>I am trying to find a running process and kill it using PSLIST and PSKILL however, I'm unable to get the errorlevel to set properly.  Depending on the way I do it, it gets stuck on either 0 or 1.  I originally had the code working the Taskkill and Tasklist commands, but the code has to run on Windows 2000 as well as XP.</p>
  
  <p>I also have notepad++ running to edit the batch file.  The following code doesn't differentiate between notepad++ or notepad.exe.</p>
  
  <pre><code>@echo off
  
  reg.exe ADD "HKCU\Software\Sysinternals\PsKill" /v EulaAccepted /t REG_DWORD /d 1 /f &gt;NUL
  reg.exe ADD "HKCU\Software\Sysinternals\PsList" /v EulaAccepted /t REG_DWORD /d 1 /f &gt;NUL
  
  rem just to see output of pslist
  PSLIST "notepad" 2&gt;NUL
  ECHO.
  ECHO. 
  PSLIST "notepad" 2&gt;NUL | FIND /I /N "notepad"
  echo The error level is %errorlevel%
  
  
  IF %errorlevel% EQU 0 (
      ECHO Notepad is running and will be terminated.
      ECHO.
      PSKILL "notepad.exe" 2&gt;NUL
  )
  IF %errorlevel% EQU 1 (
      ECHO Notepad was not running.
      ECHO Starting Notepad now...
      ECHO.
      start "" "notepad.exe"
  )
  
  Pause
  EXIT
  </code></pre>
  
  <p>The above code gets stuck on 0. When I change the line with FIND command to FINDSTR as <code>PSLIST "notepad" 2&gt;NUL | FINDSTR /I /N "notepad.exe"</code> then it gets stuck on 1.</p>
  
  <p>Is there a way to get the PSLIST and FIND or FINDSTR command to return the correct errorlevel with an exact match? </p>