Hi, does anyone have an example of useing NetUserEnum with USER_INFO_3 structure
? I have one, but it does not work.

Thanks

===========================================================
Here is my Example:


Private Type USER_INFO_3
usri3_name As Long
usri3_password As Long
usri3_password_age As Long
usri3_priv As Long
usri3_home_dir As Long
usri3_comment As Long
usri3_flags As Long
usri3_script_path As Long
usri3_auth_flags As Long
usri3_full_name As Long
usri3_usr_comment As Long
usri3_parms As Long
usri3_workstations As Long
usri3_last_logon As Long
usri3_last_logoff As Long
usri3_acct_expires As Long
usri3_max_storage As Long
usri3_units_per_week As Long
usri3_logon_hours As Long
usri3_bad_pw_count As Long
usri3_num_logons As Long
usri3_logon_server As Long
usri3_country_code As Long
usri3_code_page As Long
usri3_user_id As Long
usri3_primary_group_id As Long
usri3_profile As Long
usri3_home_dir_drive As Long
usri3_password_expired As Long

End Type


Private Declare Function apiNetUserEnum _
Lib "netapi32.DLL" Alias "NetUserEnum" _
(ByVal servername As Long, _
ByVal level As Long, _
ByVal filter As Long, _
bufptr As Long, _
ByVal prefmaxlen As Long, _
entriesread As Long, _
totalentries As Long, _
resume_handle As Long) _
As Long

Private Declare Function apiNetAPIBufferFree _
Lib "netapi32.DLL" Alias "NetApiBufferFree" _
(ByVal buffer As Long) _
As Long

Private Declare Function apilstrlenW _
Lib "kernel32" Alias "lstrlenW" _
(ByVal lpString As Long) _
As Long

Private Declare Sub sapiCopyMem _
Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)

Private Const FILTER_TEMP_DUPLICATE_ACCOUNT = &H1&
Private Const FILTER_NORMAL_ACCOUNT = &H2&
Private Const FILTER_INTERDOMAIN_TRUST_ACCOUNT = &H8&
Private Const FILTER_WORKSTATION_TRUST_ACCOUNT = &H10&
Private Const FILTER_SERVER_TRUST_ACCOUNT = &H20&
Private Const MAX_PREFERRED_LENGTH = -1&

Private Const NERR_SUCCESS = 0
Private Const ERROR_MORE_DATA = 234&
Private Const NERR_BASE = 2100
Private Const NERR_InvalidComputer = (NERR_BASE + 251)
Private Const ERROR_BAD_NETPATH = 53&
Private Const ERROR_INVALID_LEVEL = 124&

Private lSeparator As Long

Function fEnumDomainUsers( _
ByVal strServerName As String) _
As Boolean
' if strServerName=vbNullString,
' assume local machine
' This code only enums global accounts
'
On Error GoTo ErrHandler

Dim abytServerName() As Byte
Dim pBuf As Long
'Dim pTmpBuf As USER_INFO_0
'Dim pTmpBuf As USER_INFO_20
Dim pTmpBuf As USER_INFO_3

Dim dwLevel As Long
Dim dwPrefMaxLen As Long
Dim dwEntriesRead As Long
Dim dwTotalEntries As Long
Dim dwResumeHandle As Long
Dim i As Long
Dim dwTotalCount As Long
Dim nStatus As Long



'''''''''''''''''''''''''''''''''
'Variables will hold user's info'
'''''''''''''''''''''''''''''''''
Dim szName As String
Dim szFullName As String
Dim szComment As String
Dim szPassword As String
Dim szPassword_age As String
Dim szPriv As String
Dim szHome_dir As String

Dim szFlags As String
Dim szScript_path As String
Dim szAuth_flags As String
Dim szUsr_comment As String
Dim szParms As String
Dim szWorkstations As String
Dim szLast_logon As String
Dim szLast_logoff As String
Dim szAcct_expires As String
Dim szMax_storage As String
Dim szUnits_per_week As String
Dim szLogon_hours As String
Dim szBad_pw_count As String
Dim szNum_logons As String
Dim szLogon_server As String
Dim szCountry_code As String
Dim szCode_page As String
Dim szUser_id As String
Dim szPrimary_group_id As String
Dim szProfile As String
Dim szHome_dir_drive As String
Dim szPassword_expired As String


Dim iRecordsAffected As Integer

' assume MAX_PREFERRED_LENGTH
dwPrefMaxLen = MAX_PREFERRED_LENGTH
abytServerName = strServerName & vbNullChar
dwLevel = 3
Do
'only global users
nStatus = apiNetUserEnum(VarPtr(abytServerName(0)), _
dwLevel, _
FILTER_NORMAL_ACCOUNT, _
pBuf, _
dwPrefMaxLen, _
dwEntriesRead, _
dwTotalEntries, _
dwResumeHandle)
'// If the call succeeds,
If ((nStatus = NERR_SUCCESS) Or (nStatus = ERROR_MORE_DATA)) Then
'// Loop through the entries.
For i = 0 To dwEntriesRead - 1
Call sapiCopyMem(pTmpBuf, ByVal (pBuf + (i * 300)), Len(pTmpBuf))

'Call sapiCopyMem(pTmpBuf, ByVal (pBuf + (i * Len(pTmpBuf))),
Len(pTmpBuf))

'// Print the name of the user account.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
szName = String$(apilstrlenW(pTmpBuf.usri3_name) * 2, vbNullChar)
szFullName = String$(apilstrlenW(pTmpBuf.usri3_full_name) *
2, vbNullChar)
szComment = String$(apilstrlenW(pTmpBuf.usri3_comment) * 2,
vbNullChar)

szAcct_expires = String$(apilstrlenW(pTmpBuf.usri3_acct_expires)
* 2, vbNullChar)
szAuth_flags = String$(apilstrlenW(pTmpBuf.usri3_auth_flags)
* 2, vbNullChar)

szBad_pw_count = String$(apilstrlenW(pTmpBuf.usri3_bad_pw_count)
* 2, vbNullChar)

szCode_page = String$(apilstrlenW(pTmpBuf.usri3_code_page)
* 2, vbNullChar)
szCountry_code = String$(apilstrlenW(pTmpBuf.usri3_country_code)
* 2, vbNullChar)

szFlags = String$(apilstrlenW(pTmpBuf.usri3_flags) * 2, vbNullChar)

szHome_dir = String$(apilstrlenW(pTmpBuf.usri3_home_dir) *
2, vbNullChar)
szHome_dir_drive = String$(apilstrlenW(pTmpBuf.usri3_home_dir_drive)
* 2, vbNullChar)

szLast_logoff = String$(apilstrlenW(pTmpBuf.usri3_last_logoff)
* 2, vbNullChar)
szLast_logon = String$(apilstrlenW(pTmpBuf.usri3_last_logon)
* 2, vbNullChar)
szLogon_hours = String$(apilstrlenW(pTmpBuf.usri3_logon_hours)
* 2, vbNullChar)
szLogon_server = String$(apilstrlenW(pTmpBuf.usri3_logon_server)
* 2, vbNullChar)

szMax_storage = String$(apilstrlenW(pTmpBuf.usri3_max_storage)
* 2, vbNullChar)

szName = String$(apilstrlenW(pTmpBuf.usri3_name) * 2, vbNullChar)
szNum_logons = String$(apilstrlenW(pTmpBuf.usri3_num_logons)
* 2, vbNullChar)

szParms = String$(apilstrlenW(pTmpBuf.usri3_parms) * 2, vbNullChar)
szPassword = String$(apilstrlenW(pTmpBuf.usri3_password) *
2, vbNullChar)
szPassword_age = String$(apilstrlenW(pTmpBuf.usri3_password_age)
* 2, vbNullChar)
szPassword_expired = String$(apilstrlenW(pTmpBuf.usri3_password_expired)
* 2, vbNullChar)
szPrimary_group_id = String$(apilstrlenW(pTmpBuf.usri3_primary_group_id)
* 2, vbNullChar)
szPriv = String$(apilstrlenW(pTmpBuf.usri3_priv) * 2, vbNullChar)
szProfile = String$(apilstrlenW(pTmpBuf.usri3_profile) * 2,
vbNullChar)

szScript_path = String$(apilstrlenW(pTmpBuf.usri3_script_path)
* 2, vbNullChar)

szUnits_per_week = String$(apilstrlenW(pTmpBuf.usri3_units_per_week)
* 2, vbNullChar)
szUser_id = String$(apilstrlenW(pTmpBuf.usri3_user_id) * 2,
vbNullChar)
szUsr_comment = String$(apilstrlenW(pTmpBuf.usri3_usr_comment)
* 2, vbNullChar)

szWorkstations = String$(apilstrlenW(pTmpBuf.usri3_workstations)
* 2, vbNullChar)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Call sapiCopyMem(ByVal szName, ByVal pTmpBuf.usri3_name, Len(szName))
Call sapiCopyMem(ByVal szFullName, ByVal pTmpBuf.usri3_full_name,
Len(szFullName))
Call sapiCopyMem(ByVal szComment, ByVal pTmpBuf.usri3_comment,
Len(szComment))

Call sapiCopyMem(ByVal szAcct_expires, ByVal pTmpBuf.usri3_acct_expires,
Len(szAcct_expires))
Call sapiCopyMem(ByVal szAuth_flags, ByVal pTmpBuf.usri3_auth_flags,
Len(szAuth_flags))
Call sapiCopyMem(ByVal szBad_pw_count, ByVal pTmpBuf.usri3_bad_pw_count,
Len(szBad_pw_count))

Call sapiCopyMem(ByVal szCode_page, ByVal pTmpBuf.usri3_code_page,
Len(szCode_page))
Call sapiCopyMem(ByVal szCountry_code, ByVal pTmpBuf.usri3_country_code,
Len(szCountry_code))

Call sapiCopyMem(ByVal szFlags, ByVal pTmpBuf.usri3_flags,
Len(szFlags))

Call sapiCopyMem(ByVal szHome_dir, ByVal pTmpBuf.usri3_home_dir,
Len(szHome_dir))
Call sapiCopyMem(ByVal szHome_dir_drive, ByVal pTmpBuf.usri3_home_dir_drive,
Len(szHome_dir_drive))

Call sapiCopyMem(ByVal szLast_logoff, ByVal pTmpBuf.usri3_last_logoff,
Len(szLast_logoff))
Call sapiCopyMem(ByVal szLast_logon, ByVal pTmpBuf.usri3_last_logon,
Len(szLast_logon))
Call sapiCopyMem(ByVal szLogon_hours, ByVal pTmpBuf.usri3_logon_hours,
Len(szLogon_hours))
Call sapiCopyMem(ByVal szLogon_server, ByVal pTmpBuf.usri3_logon_server,
Len(szLogon_server))

Call sapiCopyMem(ByVal szMax_storage, ByVal pTmpBuf.usri3_max_storage,
Len(szMax_storage))
Call sapiCopyMem(ByVal szName, ByVal pTmpBuf.usri3_name, Len(szName))
Call sapiCopyMem(ByVal szNum_logons, ByVal pTmpBuf.usri3_num_logons,
Len(szNum_logons))

Call sapiCopyMem(ByVal szParms, ByVal pTmpBuf.usri3_parms,
Len(szParms))
Call sapiCopyMem(ByVal szPassword, ByVal pTmpBuf.usri3_password,
Len(szPassword))
Call sapiCopyMem(ByVal szPassword_age, ByVal pTmpBuf.usri3_password_age,
Len(szPassword_age))
Call sapiCopyMem(ByVal szPassword_expired, ByVal pTmpBuf.usri3_password_expired,
Len(szPassword_expired))
Call sapiCopyMem(ByVal szPrimary_group_id, ByVal pTmpBuf.usri3_primary_group_id,
Len(szPrimary_group_id))
Call sapiCopyMem(ByVal szPriv, ByVal pTmpBuf.usri3_priv, Len(szPriv))
Call sapiCopyMem(ByVal szProfile, ByVal pTmpBuf.usri3_profile,
Len(szProfile))

Call sapiCopyMem(ByVal szScript_path, ByVal pTmpBuf.usri3_script_path,
Len(szScript_path))
Call sapiCopyMem(ByVal szUnits_per_week, ByVal pTmpBuf.usri3_units_per_week,
Len(szUnits_per_week))
Call sapiCopyMem(ByVal szUser_id, ByVal pTmpBuf.usri3_user_id,
Len(szUser_id))
Call sapiCopyMem(ByVal szUsr_comment, ByVal pTmpBuf.usri3_usr_comment,
Len(szUsr_comment))
Call sapiCopyMem(ByVal szWorkstations, ByVal pTmpBuf.usri3_workstations,
Len(szWorkstations))

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''

Debug.Print StrConv(szAcct_expires, vbFromUnicode)
Debug.Print StrConv(szAuth_flags, vbFromUnicode)
Debug.Print StrConv(szBad_pw_count, vbFromUnicode)
Debug.Print StrConv(szCode_page, vbFromUnicode)
Debug.Print StrConv(szComment, vbFromUnicode)
Debug.Print StrConv(szCountry_code, vbFromUnicode)
Debug.Print StrConv(szFlags, vbFromUnicode)
Debug.Print StrConv(szFullName, vbFromUnicode)
Debug.Print StrConv(szHome_dir, vbFromUnicode)
Debug.Print StrConv(szHome_dir_drive, vbFromUnicode)
Debug.Print StrConv(szLast_logoff, vbFromUnicode)
Debug.Print StrConv(szLast_logon, vbFromUnicode)
Debug.Print StrConv(szLogon_hours, vbFromUnicode)
Debug.Print StrConv(szLogon_server, vbFromUnicode)
Debug.Print StrConv(szMax_storage, vbFromUnicode)
Debug.Print StrConv(szName, vbFromUnicode)
Debug.Print StrConv(szNum_logons, vbFromUnicode)
Debug.Print StrConv(szParms, vbFromUnicode)
Debug.Print StrConv(szPassword, vbFromUnicode)
Debug.Print StrConv(szPassword_age, vbFromUnicode)
Debug.Print StrConv(szPassword_expired, vbFromUnicode)
Debug.Print StrConv(szPrimary_group_id, vbFromUnicode)
Debug.Print StrConv(szPriv, vbFromUnicode)
Debug.Print StrConv(szProfile, vbFromUnicode)
Debug.Print StrConv(szScript_path, vbFromUnicode)
Debug.Print StrConv(szUnits_per_week, vbFromUnicode)
Debug.Print StrConv(szUser_id, vbFromUnicode)
Debug.Print StrConv(szUsr_comment, vbFromUnicode)
Debug.Print StrConv(szWorkstations, vbFromUnicode)

'szName = StrConv(szName, vbFromUnicode)
'szFullName = StrConv(szFullName, vbFromUnicode)
'szComment = StrConv(szComment, vbFromUnicode)

'szPassword = StrConv(szPassword, vbFromUnicode)
'szPassword_age = StrConv(szPassword_age, vbFromUnicode)
'szPassword_expired = StrConv(szPassword_expired, vbFromUnicode)

'lSeparator = InStr(szFullName, " ")
'Debug.Print Left(szFullName, lSeparator)
'Debug.Print Right(szFullName, lSeparator)



dwTotalCount = dwTotalCount + 1
Next
End If

MsgBox dwTotalCount

If (nStatus = NERR_InvalidComputer) Then
'Invalid computer
fEnumDomainUsers = False
MsgBox "Invalid computer"
Exit Function
End If


If (nStatus = ERROR_BAD_NETPATH) Then
'Invalid computer
fEnumDomainUsers = False
MsgBox "BAD NETPATH"
Exit Function

End If
Call apiNetAPIBufferFree(pBuf)
pBuf = 0
Loop While (nStatus = ERROR_MORE_DATA)
If Not (pBuf = 0) Then Call apiNetAPIBufferFree(pBuf)

fEnumDomainUsers = True
ExitHere:
Exit Function
ErrHandler:
fEnumDomainUsers = False
Resume ExitHere
End Function

Private Sub Form_Load()

fEnumDomainUsers ("\\ServerName")

End Sub