title: Access denied when reading / writing to network location as a remote process
body: <p>I'm currently trying to launch a process on a remote machine using WMI in C#. The process reads and writes to a file that is stored on a separate server.</p>
  
  <p>When I manually login to the remote machine, I can run the process and it all works fine.</p>
  
  <p>However, when I try to launch the process on the remote from my local machine using WMI, I get the following error:</p>
  
  <pre><code>System.UnauthorizedAccessException: Access to the path '\\server\path\input.txt' is denied.
  </code></pre>
  
  <p>I've tried multiple connection options, but I'm not sure how to re-create the permissions that I seem to have when I login manually... What do I need to do?</p>
  
  <p><strong>Local machine code</strong></p>
  
  <pre><code>static void LaunchRemoteProcess(string remoteMachine, string command)
  {
      ConnectionOptions connectionOptions = new ConnectionOptions
      {
          Impersonation = ImpersonationLevel.Impersonate,
          EnablePrivileges = true
      };
  
      var managementScope = new ManagementScope(string.Format(@"\\{0}\root\cimv2", remoteMachine), connectionOptions);
      managementScope.Connect();
      var managementPath = new ManagementPath("Win32_Process");
      var objectGetOptions = new ObjectGetOptions();
      var managementClass = new ManagementClass(managementScope, managementPath, objectGetOptions);
  
      // Launch the command asynchronously
      var inParams = managementClass.GetMethodParameters("Create");
      inParams["CommandLine"] = command;
      var outParams = managementClass.InvokeMethod("Create", inParams, null);
  }
  </code></pre>
  
  <p><strong>Remote machine code</strong></p>
  
  <pre><code>string networkPath = @"\\server\path";
  string inputFile = "input.txt";
  string inputText = File.ReadAllText(Path.Combine(networkPath, inputFile));
  
  string outputFile = "output.txt";
  File.WriteAllText(Path.Combine(networkPath, outputFile), inputText);
  </code></pre>
  
  <p><strong>Edit 1</strong></p>
  
  <p>I have already tried using the credentials of the user for which the process works if I log on to the remote machine manually and the process still fails with the same error:</p>
  
  <pre><code>    ConnectionOptions connectionOptions = new ConnectionOptions
      {
          Username = "username",
          Password = "password",
          Authority = "ntlmdomain:COMPANYNAME.CO.UK,
          EnablePrivileges = true
      };
  </code></pre>
  
  <p>Am I missing something with regards to the <code>Authority</code>, <code>Authentication</code>, or <code>Impersonation</code> attributes?</p>