title: Mapping a network drive without hardcoding a drive letter in a batch file
body: <p>I need to map a network drive with a batch file, but don't want to specify the drive letter.</p>
  
  <p>The batch file is used as part of a deployment process; I call the batch file from <code>CruiseControl.Net</code>, the batch file needs to map a UNC path which requires credentials to authenticate. Then the batch file calls <code>RoboCopy</code> to deploy the website from the output directory to the destination (and excludes some files and folders). Finally the batch deletes the network drive.</p>
  
  <p>The problem is that this isn't scalable, it's fine when there are only a few projects but we've now got 20 projects using this approach and are running out of drive letters to map. I don't want to re-use drive letters as they could collide - which would be bad.</p>
  
  <p>This is an example of the batch file:</p>
  
  <pre><code>@echo off
  net use x: \\192.168.0.1\Share\wwwroot\MyProject /user:mydomain\myuser MyP455w0rd
  robocopy.exe "W:\wwwroot\MyProject" x:\ *.* /E /XO /XD "App_Data/Search" "*.svn" /XF "sitefinity.log" "Thumbs.db" /NDL /NC /NP
  net use x: /delete
  </code></pre>
  
  <p>and formatted for readability:</p>
  
  <pre><code>@echo off
  net use x: \\192.168.0.1\Share\wwwroot\MyProject 
      /user:mydomain\myuser MyP455w0rd
  robocopy.exe "W:\wwwroot\MyProject" x:\ *.* /E /XO /XD 
      "App_Data/Search" "*.svn" /XF "sitefinity.log" "Thumbs.db" /NDL /NC /NP
  net use x: /delete
  </code></pre>