title: "Access Denied" trying to execute a command using alternate credentials
body: <p>Due to reasons I won't bore you with, I'm locked into a very narrow set of circumstances to solve this problem.  The root problem is simple:  I need to copy the contents of a remote share to the local drive of a computer that has no current user, from BES.  BES runs as SYSTEM, which has no access to this share, so I have to access it using alternative credentials (which are easy to provide).  And I can't run as a service because the moment the service takes it, BES moves on and reboots the box, before the copy can complete.</p>
  
  <p>TLDR; Need to execute a command using alternative credentials and it's not working.</p>
  
  <p>I'm trying Powershell (but am open to darn near anything).  Here's my script:</p>
  
  <pre><code>$username = "username"
  $password = "password"
  $credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
  Start-Process testbat.cmd -WorkingDirectory c:\temp\runas -Credential ($credentials)
  </code></pre>
  
  <p>If I'm logged into the box and run this, on any account, it runs and uses the credentials I provide.  However, if I run the script as SYSTEM (how the script will be run), I get:</p>
  
  <blockquote>
    <p>Start-Process : This command cannot be executed due to the error: Access is denied.
    At C:\temp\runas\testrun.ps1:5 char:14<br>
    + Start-Process &lt;&lt;&lt;&lt;  testbat.cmd -WorkingDirectory c:\temp\runas -Credential (
    $credentials)<br>
        + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException<br>
        + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand</p>
  </blockquote>
  
  <p>Again, I'm open to almost anything, VBS, batch, etc.  I just can't:</p>
  
  <ol>
  <li>Run it as a service, because BES considers the process "done" the moment it hands it off</li>
  <li>Add any .exe's (it's a closed manufacturing environment) or foreign applications</li>
  </ol>
  
  <p>Any wisdom, guidance, or just plain bonking me in the head for making a dumb mistake is appreciated.  I've not done much power shell, but I love how easy it is.  I've done a few scripts but this is my first hard stop.</p>
  
  <p>Thanks in advance.</p>