title: Run batch file remotely as administrator using psexec in C#
body: <p>I have a .bat file on the remote machine. when i run manually cmd as admin, executed psexec works correctly. But in C#, i stuck somewhere. I would like to run this .bat file as administrator in C# code. Here is my code. Could someone help me, please?</p>
  
  <pre><code>    public void CopyAtoBFolder()
      {
          int waitForExit = 1000 * 300;
          string localDestinationFolderPath = @"D:\Tool\";
  
          string call = localDestinationFolderPath + "CopyAtoBFolder.bat";
          Process process = new Process();
  
          process.StartInfo.FileName = this.path + @"\PsExec.exe";
          process.StartInfo.Arguments = "-accepteula " + localDestinationFolderPath + @" \\" + ip + " -i -u " + username + " -p " + password + " " + call;
          process.StartInfo.RedirectStandardOutput = true;
          process.StartInfo.UseShellExecute = false;
          process.Start();
          process.BeginOutputReadLine();
  
          var ended = process.WaitForExit(waitForExit);
          if (!ended)
          {
              throw new TifPcbaException("Process timed out.");
          }
          int resultReturnCode = process.ExitCode;
          if (resultReturnCode != 0)
          {
              throw new TifPcbaException("PSExec return code " + resultReturnCode + " shows an error calling " + call + Environment.NewLine);
          }
      }
  </code></pre>
  
  <p>And here is the error.
  <strong>PSExec return code 6 shows an error calling D:\Tool\CopyAtoBFolder.bat</strong></p>