title: Robocopy from Process sometimes Gives Access Denied, Not in BAtch File
body: <p>We're running a Robocopy through a Process, so we can look at the log file after the Robocopy command fails. Sometimes, the Robocopy will give Access Denied. It's very inconsistent when the Access Denied happens. Running using an admin acct. Here's the code ...</p>
  
  <pre><code>            using (Process p = new Process())
              {
                  Globals.lastCommand = string.Format("/C ROBOCOPY \"{0}\" \"{1}\" /MIR /J /LOG+:\"{2}\" /R:1 /W:10 /XF {3}", source, destination, Globals.tempLog, "*.bak");
                  p.StartInfo.Arguments = Globals.lastCommand;
                  p.StartInfo.Domain = "++++++++";
                  p.StartInfo.UserName = "+++++++";
                  string password = "++++++++";
                  for (int x = 0; x &lt; password.Length; x++)
                      ssPwd.AppendChar(password[x]);
                  p.StartInfo.Password = ssPwd;
                  p.StartInfo.WorkingDirectory = source;
                  p.StartInfo.FileName = "CMD.EXE";
                  p.StartInfo.CreateNoWindow = true;
                  p.StartInfo.Verb = "runas";
                  p.StartInfo.UseShellExecute = false;
                  p.Start();
                  p.WaitForExit();
              }
  </code></pre>
  
  <p>Here's the error we're getting:</p>
  
  <pre><code>                   2    \\MAD2014\SYNC\017 Alliance\004 Sebree Mining\917-5026\(0016) MA 10\DMP\MPA03\ARCHIVE\9175026_MA10_042914\
                     2    \\MAD2014\SYNC\017 Alliance\004 Sebree Mining\917-5026\(0016) MA 10\DMP\MPA03\ARCHIVE\9175026_MI10_110213\
                     6    \\MAD2014\SYNC\017 Alliance\004 Sebree Mining\917-5026\(0016) MA 10\DMP\MPA03\ARCHIVE\9175026_MI10_110213\SHP_FILES_9175026_MI10\
                     0    \\MAD2014\SYNC\017 Alliance\004 Sebree Mining\917-5026\(0016) MA 10\DMP\MPA03\COLLECTION\
                    12    \\MAD2014\SYNC\017 Alliance\004 Sebree Mining\917-5026\(0016) MA 10\DMP\MPA03\COLLECTION\Correspondence\
  </code></pre>
  
  <p>2014/07/27 20:31:49 ERROR 5 (0x00000005) Accessing Destination Directory \lex2014\projects\017 Alliance\004 Sebree Mining\917-5026(0016) MA 10\DMP\MPA03\COLLECTION\Correspondence\
  Access is denied.</p>
  
  <p>Waiting 10 seconds... Retrying...
  2014/07/27 20:31:59 ERROR 5 (0x00000005) Accessing Destination Directory \lex2014\projects\017 Alliance\004 Sebree Mining\917-5026(0016) MA 10\DMP\MPA03\COLLECTION\Correspondence\
  Access is denied.</p>
  
  <p>ERROR: RETRY LIMIT EXCEEDED.</p>
  
  <pre><code>                   6    \\MAD2014\SYNC\017 Alliance\004 Sebree Mining\917-5026\(0016) MA 10\DMP\MPA03\COLLECTION\ITEM_08\
                     5    \\MAD2014\SYNC\017 Alliance\004 Sebree Mining\917-5026\(0016) MA 10\DMP\MPA03\COLLECTION\ITEM_09\
  </code></pre>
  
  <p>Notice how it continues. Also, if the same Robocopy is run in a batch file, no errors. Also, we're copying from one server to the other.</p>