title: Getting the Current username when impersonated
body: <p>I am using something like the following method to impersonate a user in my code:</p>
  
  <p><a href="https://stackoverflow.com/questions/125341/impersonation-in-net">How do you do Impersonation in .NET?</a></p>
  
  <p>In another class, I need to find out the current user (like "mydomain\moose"), but I won't have any idea if I'm currently impersonating another user or not.</p>
  
  <p>How do I get the username, if I'm impersonating someone?</p>
  
  <p>System.Environment.UserName and System.Security.Principal.WindowsIdentity.GetCurrent().Name both return the original user, not the currently impersonated user.</p>
  
  <p>More Details:</p>
  
  <p>I am doing this impersonation so that I can access some files in a netowrk share the user usually does not have access to.</p>
  
  <p>If I use a logon type of LOGON32_LOGON_INTERACTIVE, I do see the new user, but I cannot access the network share. If I use a logon type of LOGON32_LOGON_NEW_CREDENTIALS (a value of 9), i can access the network share but I don't see the new user in Environment.UserName.</p>