title: Conditional PAUSE (not in command line)
body: <p>I like to have a final <code>PAUSE</code> in my *.bat scripts so I can just double click on them in Windows explorer and have the chance to read the output. However, the final PAUSE is an annoyance when I run the same script from the command line.</p>
  
  <p>Is there any way to detect whether we are running the script from a command prompt (or not) and insert the PAUSE (or not) accordingly?</p>
  
  <p>(Target environment is Windows XP and greater.)</p>
  
  <h1>Update</h1>
  
  <p>I've managed to compose this from Anders's answer:</p>
  
  <pre><code>(((echo.%cmdcmdline%)|find /I "%~0")&gt;nul)
  if %errorlevel% equ 0 (
      set GUI=1
  ) else (
      set CLI=1
  )
  </code></pre>
  
  <p>Then, I can do stuff like this:</p>
  
  <pre><code>if defined GUI pause
  </code></pre>