
Getting the full user name under Win NT
This code is courtesy of Jeff Hong YAN. Enjoy.
Type TUser11
ptrName As Long
ptrComment As Long
ptrUsrComment As Long
ptrFullName As Long
dwPriv As Long
dwAuthFlags As Long
dwPasswordAge As Long
ptrHomeDir As Long
ptrParms As Long
dwLastLogon As Long
dwLastLogoff As Long
dwBadPwCount As Long
dwNumLogons As Long
ptrLogonServer As Long
dwCountryCode As Long
ptrWorkstations As Long
dwMaxStorage As Long
dwUnitsPerWeek As Long
ptrLogonHours As Long
dwCodePage As Long
End Type '} USER_INFO_11, *PUSER_INFO_11, *LPUSER_INFO_11;
Function GetUserFullName(sUserID As String) As String
Dim swServer As String * 255
Dim swUserID As String * 255
Dim lReturn As Long
Dim ptmpBuffer As Long
Dim ptr As Long
Dim sUserFullName As String
Dim sUser As String
Dim sByte() As Byte
ReDim sByte(255)
swUserID = StrConv(sUserID & vbNullChar, vbUnicode)
swServer = StrConv(vbNullChar, vbUnicode)
Dim tmpBuffer As TUser11
lReturn = MyNetUserGetInfo(swServer, swUserID, 11&, ptmpBuffer)
RtlMoveMemory tmpBuffer, ptmpBuffer, LenB(tmpBuffer)
ptr = tmpBuffer.ptrFullName
If ptr <> 0 Then
RtlMoveMemory sByte(0), ptr, 256
sUser = vbNullString
sUser = sByte
sUser = sUser & vbNullChar
Else
sUser = "(Unknown)"
End If
sUserFullName = Left$(sUser, InStr(sUser, Chr$(0)) - 1)
Call NetAPIBufferFree(ptmpBuffer)
Debug.Print "Full Name = " & sUserFullName
GetUserFullName = sUserFullName
End Function
Quote:
> Hello
> In VB 4 or VB 5, I need to get the full user name in Windows NT.
> I've already gotten the account name by calling WNetGetUser, but I need
to
> get the data from the Full Name field from the NT User Manager.
> I know that it's possible to do in C++, but I was having trouble porting
> the code to VB. Does anyone have any experience/ideas/code?
> Thanks,
> --
> Ilya Haykinson