Sunday, May 19, 2013
 
    Search Web Link
Search Software
    
API Home » Network » NetUserGetInfo

NetUserGetInfo

Category: Network
Hits: 5128 Rating: NetUserGetInfo has been rated 2.88 by  508 users (2.88) votes 508
Rate: 1-star  2-stars  3-stars  4-stars  5-stars
E-mail this API to friend E-mail this Code to a friend  save Bookmark this VB API Function
API Explanation
The NetUserGetInfo function retrieves information about a particular user account on a server.

Parameter Information
Declare Function NetUserGetInfo Lib "netapi32" (ByVal servername As String, ByVal username As String, ByVal level As Long, bufptr As Long) As Long

· servername
[in] Pointer to a constant Unicode string specifying the name of the remote server on which the function is to execute. The string must begin with \\. If this parameter is NULL, the local computer is used.

· username
[in] Pointer to a constant Unicode string containing the name of the user account for which to return information.

· level
[in] Specifies the information level of the data. This parameter can be one of the following values.
0
Return the user account name. The bufptr parameter points to a USER_INFO_0 structure.
1
Return detailed information about the user account. The bufptr parameter points to a USER_INFO_1 structure.
2
Return level one information and additional attributes about the user account. The bufptr parameter points to a USER_INFO_2 structure.
3
Return level two information and additional attributes about the user account. This level is valid only on Windows NT/Windows 2000 servers. The bufptr parameter points to a USER_INFO_3 structure.
10
Return user and account names and comments. The bufptr parameter points to a USER_INFO_10 structure.
11
Return detailed information about the user account. The bufptr parameter points to a USER_INFO_11 structure.
20
Return the user's name and identifier and various account attributes. The bufptr parameter points to a USER_INFO_20 structure.

· bufptr
[out] Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. This buffer is allocated by the system and must be freed using the NetApiBufferFree function.
Code



Const NERR_Success = 0
Private Const NERR_BASE = 2100
Private Const NERR_InvalidComputer = (NERR_BASE + 251)
Private Const NERR_UseNotFound = (NERR_BASE + 150)
Const CP_ACP = 0

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 Byte
usri3_bad_pw_count As Long
usri3_num_logons As Long
usri3_logon_server As String
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 NetUserGetInfo Lib "netapi32" (lpServer As Any, UserName As Byte, ByVal Level As Long, lpBuffer As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
Private Declare Function lstrlenW Lib "kernel32" (lpString As Any) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal codepage As Long, ByVal dwFlags As Long, lpWideCharStr As Any, ByVal cchWideChar As Long, lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long

' Returns an ANSI string from a pointer to a Unicode string.
Public Function GetStrFromPtrW(lpszW As Long) As String
Dim sRtn As String
sRtn = String$(lstrlenW(ByVal lpszW) * 2, 0) ' 2 bytes/char
' WideCharToMultiByte also returns Unicode string length
Call WideCharToMultiByte(CP_ACP, 0, ByVal lpszW, -1, ByVal sRtn, Len(sRtn), 0, 0)
GetStrFromPtrW = GetStrFromBufferA(sRtn)
End Function

' Returns the string before first null char encountered (if any) from an ANSII string.
Public Function GetStrFromBufferA(sz As String) As String
If InStr(sz, vbNullChar) Then
GetStrFromBufferA = Left$(sz, InStr(sz, vbNullChar) - 1)
Else
' If sz had no null char, the Left$ function
' above would return a zero length string ("").
GetStrFromBufferA = sz
End If
End Function

Private Sub Form_Load()
Dim lpBuf As Long
Dim ui3 As USER_INFO_3
' replace "Administrator" with a valid NT username
Dim bServer() As Byte, bUsername() As Byte
bServer = "" & vbNullChar
bUsername = "Administrator" & vbNullChar
If (NetUserGetInfo(bServer(0), bUsername(0), 3, lpBuf) = NERR_Success) Then
Call MoveMemory(ui3, ByVal lpBuf, Len(ui3))
MsgBox GetStrFromPtrW(ui3.usri3_name)
MsgBox GetStrFromPtrW(ui3.usri3_comment)
Call NetApiBufferFree(ByVal lpBuf)
End If
End Sub





HOME | MUSIC | DOWNLOADS |  GAMES | TEST-QUIZZES | SITEMAP | ABOUT | HELP
Copyright © 2000 - 2013 Ex-designz. All rights reserved. Website Developed By Dexter Zafra of Myasp-net.com
Link to us | Advertisement | Contact us | Privacy Policy | Terms of use | Accessibility