Obtain the DomainName and UserName of the currently logged in user.
[C#]
///<summary>Obtain the DomainName and UserName of the currently logged in user.</summary>
///
///<returns>A System.String that is the user's DomainName\UserName.</returns>
///
///<remarks></remarks>
public System.String GetDomainNameUserName()
{
System.Security.Principal.WindowsIdentity windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
System.String windowsLoginName = windowsIdentity.Name;
return windowsLoginName;
}
[Visual Basic .NET]
'''<summary>Obtain the DomainName and UserName of the currently logged in user.</summary> ''' '''<returns>A System.String that is the user's DomainName\UserName.</returns> ''' '''<remarks></remarks> Public Function GetDomainNameUserName() As System.String Dim windowsIdentity As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent Dim windowsLoginName As System.String = windowsIdentity.Name Return windowsLoginName End Function