LocationMy.User.Name SyntaxDim result As String = My.User.Name DescriptionThe 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
ExampleThe 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 AlsoCurrentPrincipal Property, InitializeWithWindowsUser Method, IsAuthenticated Property, IsInRole Method, Name Property (My.Computer), User Object |