17

Problem is if this process doesn't exist, build fails. I try to write something like this

tasklist /nh /fi "imagename eq XDesProc.exe" | find /i "XDesProc.exe" && (
TASKKILL /F /IM "XDesProc.exe"
) || (
echo XAML designer is not running
)

But ERRORLEVEL is equal to 1 too and bild fails if XDesProc.exe is not running.

Eugene Maksimov
  • 1,504
  • 17
  • 36

1 Answers1

37

You could use a conditional test on the PID to avoid this:

  taskkill /f /fi "pid gt 0" /im xdesproc.exe
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • I appreciate this entry as it helped me as well. I want to ensure I understand correctly what is occurring so to clarify is this read as, forcefully kill all processes who's process ID is greater than 0 AND who's name is xdesproc.exe? I'm not clear on the syntax of the filters in this case, are subsequent filters delimited by the space? Thank you – TargetofGravity Nov 22 '17 at 14:43
  • To further elaborate, apologies I missed my window of editing comments, 'taskkill /?' examples seem to indicate each filters is defined by its own '/fi' prefix. If that is the case then wouldn't an attempt to kill xdesproc.exe still occur and if not in the returned filtered list wouldn't it fail as the process isn't found? – TargetofGravity Nov 22 '17 at 14:54