Link to home
Start Free TrialLog in
Avatar of Harter
HarterFlag for United States of America

asked on

what is the code in VB to get current user logon in windows?

what is the code in VB to get current user logon in windows?
here is the code I am using
Function GetUserName() As String

    If TypeOf My.User.CurrentPrincipal Is Security.Principal.WindowsPrincipal Then

        ' The application is using Windows authentication.

        ' The name format is DOMAIN\USERNAME.

        Dim parts() As String
        parts() = Split(My.User.name, "\")

        Dim username As String
        username = parts(1)

        Return username

    Else

        ' The application is using custom authentication.

        Return My.User.Name

    End If

End Function

'Dim name As String
    'name = My.User.name
    'MsgBox (name)
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial