title: selenium web driver running as different user not getting profile/session of user
body: <p>I have a strange situation where I have modified the selenium web driver code slightly to allow the driver service to be launched under a different user, changes to the code from github are:</p>
  
  <pre><code>public void Start()
      {
          this.driverServiceProcess = new Process();
          if (this.user != null)
          {
              this.driverServiceProcess.StartInfo.UserName = user.Name;
              this.driverServiceProcess.StartInfo.Password = user.Password;
              this.driverServiceProcess.StartInfo.Domain = user.Domain;
          }
          this.driverServiceProcess.StartInfo.FileName = Path.Combine(this.driverServicePath, this.driverServiceExecutableName);
          this.driverServiceProcess.StartInfo.Arguments = this.CommandLineArguments;
          this.driverServiceProcess.StartInfo.UseShellExecute = false;
          this.driverServiceProcess.StartInfo.CreateNoWindow = this.hideCommandPromptWindow;
          this.driverServiceProcess.Start();
          bool serviceAvailable = this.WaitForServiceInitialization();
  
          if (!serviceAvailable)
          {
              string msg = "Cannot start the driver service on " + this.ServiceUrl;
              throw new WebDriverException(msg);
          }
      }
  </code></pre>
  
  <p>where the user details are passed in from my external code in the call to instantiate the web driver:</p>
  
  <pre><code>new ChromeDriver(userName, password, domain);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>new InternetExplorerDriver(ieOptions, userName, password, domain);
  </code></pre>
  
  <p>and propagated through.</p>
  
  <p>This successfully launches the chrome driver under the required user credentials, but has a problem with IE.  </p>
  
  <p>Additionally the chrome driver does not have the same behavior as chrome launched as the given user manually (i.e. not through a selenium driver).  Specifically the automatic passing of user credentials on an NTLM challenge does not occur.</p>
  
  <p>I have discovered that if I have an interactive session running as the desired user (simply use <code>runas /user:&lt;theUser&gt; cmd.exe</code> from the command line and leave the session open) then all of the functionality of the the browsers is as expected when launched through the selenium web driver, including automatically responding to the NTLM challenge.</p>
  
  <p>If I use <code>Process.Start()</code> to launch cmd.exe as the desired user before creating the web driver this does not work.</p>
  
  <p>My question is this:</p>
  
  <p>What is different about launching a process programatically (using <code>Process.Start()</code>) compared to launching an interactive session of the process from the command line?  </p>
  
  <p>And is there any way I can faithfully reproduce the effect of launching a session from the command line in code so that I can automate the process and get my web drivers to perform as I desire?</p>
  
  <p><em>note: I tried launching the webdriver using .net impersonation (as suggested <a href="https://stackoverflow.com/questions/16590207/how-to-impersonate-a-specific-user-with-selenium-webdriver">here</a> and <a href="https://stackoverflow.com/questions/28045870/how-can-i-run-internet-explorer-selenium-tests-as-a-specific-domain-user/37573629#37573629">here</a>) rather than modifying the selenium code to run the driver service under another user, but the requests sent from the driver to a server were all sent under my user rather than the one specified by the impersonation (see <a href="https://stackoverflow.com/questions/39390102/launching-selenium-webdriver-with-windowsimpersonationcontext">here</a>)</em></p>