Results 1 to 4 of 4

Thread: GetUserNameEx (Windows 2000) Problem

  1. #1

    Thread Starter
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I'm trying to use the following Windows 2000 API call. It returns an error (retval = 0) when I pass it any EXTENDED_NAME_FORMAT besides NameSamCompatible. Why is that? Is there some security API call I'd have to call first? The MSDN documentation looks like they all should work.

    Thanks,
    Josh

    Code:
    Private Enum EXTENDED_NAME_FORMAT
        NameUnknown = 0 '???
        NameFullyQualifiedDN = 1 'Full Active Directory style name?
        NameSamCompatible = 2 'NT 4 style DOMAIN\user
        NameDisplay = 3 'Friendly Name?
        NameUniqueId = 6
        NameCanonical = 7
        NameUserPrincipal = 8
        NameCanonicalEx = 9
        NameServicePrincipal = 10
    End Enum
    
    Private Declare Function GetUserNameEx Lib "secur32.dll" Alias "GetUserNameExA" _
        (ByVal NameFormat As EXTENDED_NAME_FORMAT, ByVal lpbuffer As String, nsize As Long) _
        As Long
    
    Private Sub Command2_Click()
        Dim username As String 'string buffer that gets User's Name
        Dim slength As Long 'length of the string buffer
        Dim retval As Long 'return value, 0 if error
        
        username = Space(255)
        slength = 255
        retval = GetUserNameEx(NameSamCompatible, username, slength)
        username = Left(username, slength - 1)
        Text2.Text = username
    End Sub
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  2. #2

    Thread Starter
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Anyone at least try this on Windows 2000 and see if they get the same results I did? I'm suspecting something to do with Active Directory...
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3
    Lively Member
    Join Date
    Nov 2000
    Location
    Québec City
    Posts
    73
    It worked fine for me

    retval = 1
    text2.text= what it should be

    I'm using windows 2k with service pack 1

    Krushstone

  4. #4

    Thread Starter
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Did you try anything besides NameSamCompatible here?

    Code:
    retval = GetUserNameEx(NameSamCompatible, username, slength)
    Nothing else seems to work.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width