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