Question:
What is the .NET (or p/invoke to an unmanaged Windows API) method call to get the current process's network identity that is used to connect to SSPI-authenticated network services, such as SQL Server?
The specific use-case I have in mind is where one can work on a non-domain-joined machine and use runas /noprofile /netonly /USER:DOMAIN\username
to launch a process which uses that DOMAIN\username
identity for network authentication instead of their local MACHINE\username
logged-on identity.
I want the method call that gives me the DOMAIN\username
identity passed to RUNAS
here.
Thanks!
To be clear, I am NOT looking for the method call to get the current user's locally logged on identity (which may be different than the network identity). This excludes System.Security.Principal.WindowsIdentity.GetCurrent().Name
and Environment.UserName
and probably System.Threading.Thread.CurrentPrincipal.Identity.Name
from being accepted answers. I will downvote any answer that incorrectly indicates any of these to be the solution, unless I am shown to be wrong here of course. :)