Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
Location
My.User.Name Syntax
Dim result As String = My.User.Name
Description
The Name property returns the name of the current user. For most Windows applications, this name will be in the format domain\user. Usage at a Glance
Example
The following example obtains the user name. This example checks if the application is using Windows or custom authentication, and it uses that information to parse the My.User.Name property. Public Function GetCurrentUserName( ) As String If TypeOf My.User.CurrentPrincipal Is _ System.Security.Principal.WindowsPrincipal Then ' ----- Windows username = "domain\user". Return Mid(My.User.Name, Instr(My.User.Name, "\") + 1) Else ' ----- Some other custom type of user. Return My.User.Name End If End Function
Related Framework Entries
See Also
CurrentPrincipal Property, InitializeWithWindowsUser Method, IsAuthenticated Property, IsInRole Method, Name Property (My.Computer), User Object |
Категории