NetUserGetInfo – API Call

NetUserGetInfo – API Call

I am using “NetUserGetInfo” API call to get the NT user profile. I use:

typedef struct _USER_INFO_3

How can I parse the “usri3_flags” member in detail?

Use this:

Option ExplicitPrivate Const UserInfo1 As Long = 1&Private Type USER_INFO_1   usri1_name              As Long   usri1_password          As Long   usri1_password_age      As Long   usri1_priv              As Long   usri1_home_dir          As Long   usri1_comment           As Long   usri1_flags             As Long   usri1_script_path       As LongEnd Type    Public Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" _   (pTo As Any, pFrom As Any, ByVal lCount As Long)Private Declare Function NetApiBufferFree Lib "netapi32.dll" _   (ByVal lngPtrBuffer As Long) As LongPrivate Declare Function NetUserGetInfo Lib "netapi32" _   (ByVal psServer As Long, ByVal psUser As Long, ByVal lLevel As Long, _   lngPtrBuffer As Long) As LongPrivate Const NERR_Success             As Long = 0&Private Const UF_ACCOUNTDISABLE        As Long = &H2Private Const UF_SCRIPT                As Long = &H1&Private Const UF_HOMEDIR_REQUIRED      As Long = &H8&Private Const UF_LOCKOUT               As Long = &H10&Private Const UF_PASSWD_NOTREQD        As Long = &H20&Private Const UF_PASSWD_CANT_CHANGE    As Long = &H40&Private Const UF_NORMAL_ACCOUNT        As Long = &H200&Private Const UF_SERVER_TRUST_ACCOUNT  As Long = &H2000&Private Const UF_DONT_EXPIRE_PASSWD    As Long = &H10000Private Const UF_MNS_LOGON_ACCOUNT     As Long = &H20000Private Const UF_TEMP_DUPLICATE_ACCOUNT      As Long = &H100&Private Const UF_INTERDOMAIN_TRUST_ACCOUNT   As Long = &H800&Private Const UF_WORKSTATION_TRUST_ACCOUNT   As Long = &H1000&Public Sub Main()   MsgBox GetUserFlags("", "Administrator")End SubPublic Function GetUserFlags(ByVal strServerName As String, _                             ByVal strUserName As String) As String   Dim typUserInfo1        As USER_INFO_1   Dim lngBuf              As Long   Dim lngSvrName          As Long   Dim lngUserName         As Long   Dim lngParmErr          As Long   Dim lngRtn              As Long   Dim lngFlags            As Long   Dim blnIsNowDisabled    As Boolean   Dim strTmp              As String      ' Convert the server name to a pointer   If Len(Trim$(strServerName)) = 0 Then      lngSvrName = 0&   Else      lngSvrName = StrPtr(strServerName)   End If      ' Convert the user name to a pointer   If Len(Trim$(lngUserName)) = 0 Then      Exit Function 'Handle the error   Else      lngUserName = StrPtr(strUserName)   End If      ' Get the user's current flags   lngRtn = NetUserGetInfo(lngSvrName, _                           lngUserName, _                           UserInfo1, _                           lngBuf)   If lngRtn = NERR_Success Then      CopyMem typUserInfo1, _              ByVal lngBuf, _              Len(typUserInfo1)      If lngBuf Then         NetApiBufferFree lngBuf      End If   Else      MsgBox "Error Number: " & lngRtn   End If   lngFlags = typUserInfo1.usri1_flags         If (lngFlags And UF_SCRIPT) Then      strTmp = "Script is executed"   Else      strTmp = "Script is NOT executed"   End If      If (lngFlags And UF_ACCOUNTDISABLE) Then      strTmp = strTmp & vbCrLf & "Account is disabled"   Else      strTmp = strTmp & vbCrLf & "Account is NOT disabled"   End If      If (lngFlags And UF_HOMEDIR_REQUIRED) Then      strTmp = strTmp & vbCrLf & "Home directory is required"   Else      strTmp = strTmp & vbCrLf & "Home directory is NOT required"   End If      If (lngFlags And UF_PASSWD_NOTREQD) Then      strTmp = strTmp & vbCrLf & "Password is NOT required"   Else      strTmp = strTmp & vbCrLf & "Password is required"   End If      If (lngFlags And UF_PASSWD_CANT_CHANGE) Then      strTmp = strTmp & vbCrLf & "User cannot change password"   Else      strTmp = strTmp & vbCrLf & "User can change password"   End If   If (lngFlags And UF_LOCKOUT) Then      strTmp = strTmp & vbCrLf & "Account is locked out"   Else      strTmp = strTmp & vbCrLf & "Account is NOT locked out"   End If      If (lngFlags And UF_DONT_EXPIRE_PASSWD) Then      If Len(strTmp) > 0 Then         strTmp = strTmp & vbCrLf & "Password never expires"      Else         strTmp = strTmp & vbCrLf & "Password does expire"      End If   End If         GetUserFlags = strTmp   End Function

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular