GetCurrentUserAndDomain .Net replacement

  • Thread starter Thread starter Ron Harter
  • Start date Start date
R

Ron Harter

Is there a .Net equivalent for the Win32 API call GetCurrentUserAndDomain?
I need to be able to get the users name at form load time in C# application
 
Hi,

Take a look at the CredentialCache.DefaultCredentials property, if this is
what you are after then you must keep in mind that for a Forms application
you will need to set the PrincipalPolicy of the AppDomain to
WindowsPrincipal

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

Hope this helps
 
¤
¤
¤ Is there a .Net equivalent for the Win32 API call GetCurrentUserAndDomain?
¤ I need to be able to get the users name at form load time in C# application

You can use System.Security.Principal.WindowsIdentity.GetCurrent.Name to return both:


Dim CurrentUserAndDomain As String() = Nothing
CurrentUserAndDomain = System.Security.Principal.WindowsIdentity.GetCurrent.Name.Split("\"c)
MsgBox(CurrentUserAndDomain(0))
MsgBox(CurrentUserAndDomain(1))


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top