Name Property (My.User)


Name Property (My.User)

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

  • This property is read-only.

  • This property returns an empty string on systems that do not support authentication, such as Windows 95 and Windows 98.

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

  • Microsoft.VisualBasic.ApplicationServices.User.Name Property

  • Microsoft.VisualBasic.ApplicationServices.WebUser.Name Property

  • System.Security.Principal.IIdentity.Name Property

See Also

CurrentPrincipal Property, InitializeWithWindowsUser Method, IsAuthenticated Property, IsInRole Method, Name Property (My.Computer), User Object




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net