title: Batch - Kill program if running, start it if it's not
body: <p>I'm trying to make a toggle batch script for a process so that if it's running it gets killed and if it's not it is started. This is what I have:</p>
  
  <pre><code>tasklist /FI "IMAGENAME eq ProcessName.exe" 2&gt;NUL | find /I /N "ProcessName.exe"&gt;NUL
  set procopen = %ERRORLEVEL%
  if "%procopen%"=="0" taskkill /im ProcessName.exe 
  if NOT "%procopen%"=="0" start "" ProcessName.exe
  </code></pre>
  
  <p>But everytime I run it, after the first if statement I receive the error:</p>
  
  <pre><code>"1"=="0") was unexpected at this time.
  </code></pre>
  
  <p>I also feel like there's a more efficient way to write this, but I'm not exactly sure how. Any help is appreciated!</p>