NetUserGetInfo – API Call

Question:
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?

Answer:
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:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job