title: Batch file to eject USB External Drive that is "in use"
body: <p>I have a batch file that copies files from and to an external hard drive. I wanted to add a section at the end of the script that would automatically eject the hard drive so it could be safely removed. I did some research and found that <code>Remove Drive</code> is my best option. I have it set up to use and working. I can write a bat file</p>
  
  <pre><code>@echo off
  RemoveDrive :E -L
  </code></pre>
  
  <p>and it works perfectly!</p>
  
  <p>However, I've hit a snag. When I add this exact line (well without the <code>@echo off</code>) to the end of my bat file, it fails to eject. My guess is that its the same problem as when you've got files open from a usb drive and try to eject it. It won't work because the system is using it. I tested this by creating a seperate bat file that ran just the <code>RemoveDrive</code> named it "RemoveDrive.bat". I then added to the end of my batch file:</p>
  
  <pre><code>pause
  call "RemoveDrive.bat"
  </code></pre>
  
  <p>When the script hit the <code>pause</code> command. I tried to run the batch file by simply clicking the icon. The eject attempt failed. I pressed any key to continue and the called bat file failed and the script (and cmd window) closed. I then double clicked the icon for "RemoveDrive.bat" and it worked.</p>
  
  <p>So after that long explanation, I was wondering if anyone had any suggestions for how to work around this. I was thinking if there was a way I could use the <code>call</code> function with some sort of delay and could close the cmd window. If I could get the cmd window to close and then have the bat file run automatically, I'm betting that would work.</p>