title: How can I kill child process using taskkill in a batch script?
body: <p>I'm capturing the PID in a variable which I kill later</p>
  
  <pre><code>  IF NOT "%SERVICE_PID%" == 0 taskkill /pid %SERVICE_PID% /t /f 
  </code></pre>
  
  <p>though everytime I do this in a batch file it makes my computer restart because it kills some system process</p>
  
  <p>the service pid should be a user defined service launched from cmd</p>
  
  <p>I dont understand why it keeps making my machine croak.</p>
  
  <p>When I run "taskkill /pid %SERVICE_PID% /t /f" on the command line it works fine! =/</p>
  
  <p>help!</p>
  
  <p>Setting SERVICE_PID</p>
  
  <pre><code>FOR /F "tokens=4 delims= " %%A IN ('sc queryex myservice ^|FIND "PID"')
   DO SET SERVICE_PID=%%A
  </code></pre>