Harter
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.Windows Principal 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)
here is the code I am using
Function GetUserName() As String
If TypeOf My.User.CurrentPrincipal Is Security.Principal.Windows
' 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.