Get Local Users Full Name

Hi All

I did post this in VB General but no-one can come up with a answer there so...

How can I get the local users full logon name under VB.Net now i.e. John Smith as opposed to SmithJ

There was a function for VB6 that would return this but under NET...




Answer this question

Get Local Users Full Name

  • JT_AnnArbor

    Very cool. I'm following up with that team to see if this might make a good snippet or addition to "My" at some point in the future. Thanks, Paul!



  • Chule


    Not a bad idea Matthew. Given the complexity of System.DirectoryServices and the LDAP provider you might want to consider exposing some of that information through "My" as well.

  • NealRM

    Daniel15 wrote:

    Well, I remember doing something similar at school with Visual Basic 6. Basically, it queries the domain controller, and gets the user's full name (eg. Daniel Lo Nigro) if you pass it the username (eg. lon01, which is my username at school)

    The code I used can be found at http://vbnet.mvps.org/code/network/netusergetinfo.htm (at least, I think that's the code, I do know I got it from VBNet). If you logon to a domain controller, then you need to type the server's name in to the box.

    This was essentially what I used under VB6. Unfortunately it doesn't port to VB.Net.



  • Strauslin

    There was no built-in function for user full name in VB6, whatever API you were using to get it should translate to .NET.
  • CB Thirumalai

    Well, I remember doing something similar at school with Visual Basic 6. Basically, it queries the domain controller, and gets the user's full name (eg. Daniel Lo Nigro) if you pass it the username (eg. lon01, which is my username at school)

    The code I used can be found at http://vbnet.mvps.org/code/network/netusergetinfo.htm (at least, I think that's the code, I do know I got it from VBNet). If you logon to a domain controller, then you need to type the server's name in to the box.


  • Rod DeValcourt

    Richard_Wolf wrote:
    There was no built-in function for user full name in VB6, whatever API you were using to get it should translate to .NET.

    Nope, it doesn't, that's why I'm looking for a .NET OK way to do it.



  • Robert Kitson

    Thanks Paul, that is perfect and exactly what I needed

  • mobiledev1


    If you're looking for the full name there are a couple different methods you can use. The below code uses System.DirectoryServices:

    Dim DomainUser As String = System.Security.Principal.WindowsIdentity.GetCurrent.Name.Replace("\", "/")
    Dim ADEntry As New
    System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)
    Dim FullName As String = ADEntry.Properties("FullName").Value



  • vkv

    The only mechanisms I'm aware of which can return the user's name will do so with the DOMAIN\USERNAME format (which is really all the machine knows about you) if using Windows auth, or just the USERNAME otherwise.  Code for that would look like this (I shamelessly stole this from MSDN):

    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 = Split(My.User.Name, "\")
        Dim username As String = parts(1)
        Return username
      Else
        ' The application is using custom authentication.
        Return My.User.Name
      End If
    End Function
    

    Some apps will collect a full name during installation, but that's up to them. 

    (My.Settings would be a good way to save and retrieve that information.)

    As far as the machine is concerned, your name is whatever you logged in as (and is presumably the

    name used for folder containing your "My Documents" folder).

    I could also see maybe querying my Exchange server (for example) to see what mailbox name

    was for DOMAIN\USERNAME, but that's not something I've done before.

     

    --Matt--*



  • Get Local Users Full Name