title: Escape percent in bat file
body: <p>I was trying to write a VPN dialer/disconnector using a batch file, but I got stuck. After some investigation I found that the presence of <code>%</code> in the password is not playing well.</p>
  
  <p>Here is the code</p>
  
  <pre><code>@echo OFF
  SET SWITCHPARSE1=%1
  SET SWITCHPARSE2=%2
  REM echo %SWITCHPARSE1%
  SHIFT
  SHIFT
  IF "SWITCHPARSE1" == "" goto Usage
  IF "SWITCHPARSE1" == "/?" goto Usage
  IF "SWITCHPARSE2" == "" goto Usage
  IF "SWITCHPARSE2" == "/?" goto Usage
  
  
  IF "%SWITCHPARSE1%" == "sl" (
      IF "%SWITCHPARSE2%" == "conn" (
          echo "inside sl conn"
          rasdial sl employee1 K%%Pxev3=)g:{#Swc9
          goto end
      ) ELSE IF "%SWITCHPARSE2%" == "disconn" (
          rasdial sl /disconnect
          goto end
      ) ELSE (
          goto Usage
      )
  ) ELSE IF "%SWITCHPARSE1%" == "off" (
          IF "%SWITCHPARSE2%" == "conn" (
          rasdial Office employee1 office123
          goto end
      ) ELSE IF "%SWITCHPARSE2%" == "disconn" (
          rasdial Office /disconnect
          goto end
      ) ELSE (
          goto Usage
      )
  ) ELSE (
      goto Usage
  )
  
  :Usage
  echo "Usage is vpnconn.bat /[sl|off] /[conn|disconn]"
  
  :end
  </code></pre>
  
  <p>In the above script I am trying to escape <code>%</code> using <code>%</code> (i.e. <code>%%</code>, reference from <a href="http://www.robvanderwoude.com/escapechars.php" rel="noreferrer">here</a>), but the bat script gives <strong>g:{#Swc9 was unexpected at this time.</strong>.</p>
  
  <p>To root cause further, I tried to double <code>%%</code> (escape <code>%</code>) in a different batch file, and it worked:</p>
  
  <pre><code>@echo OFF
  rasdial sl employee1 K%%Pxev3=)g:{#Swc9
  </code></pre>
  
  <p>Why does the same script when integrated to work with different connections not work?</p>