LISTING 4: The AddUser Function BEGIN CALLOUT A Public Function AddUser(stSName As String, stUName As String, _ stPWD As String, stFName As String, Optional stComment As String, _ Optional stHPath As String, Optional stProf As String, _ Optional stScr As String, Optional stHDrive As String) As Long END CALLOUT A . . . '* Create null terminated strings and move data to byte arrays btSNArray = stSName & vbNullChar btUNArray = stUName & vbNullChar . . . '* Handle optional parameters If stComment = Null Or IsNull(stComment) Then btCommentArray = "" & vbNullChar Else btCommentArray = stComment & vbNullChar End If . . . BEGIN CALLOUT B '* Allocate buffer space for data lgResult = NetAPIBufferAllocate(UBound(btUNArray) + 1, lgUNPtr) lgResult = NetAPIBufferAllocate(UBound(btPWDArray) + 1, lgPWDPtr) END CALLOUT B . . . '* Copy data arrays to the buffer lgResult = StrToPtr(lgUNPtr, btUNArray(0)) lgResult = StrToPtr(lgPWDPtr, btPWDArray(0)) . . . '* Fill the data structure With UserStruct '* Direct user input values .lgUsri3_name = lgUNPtr .lgUsri3_full_name = lgFNPtr . . . '* Default settings or settings BUC copied from template account .lgUsri3_logon_hours = lgHourPtr . . . .lgUsri3_password_expired = CLng(stUserInfo(password_expired)) . . . '* Change these codes for applications that don't use US English .lgUsri3_country_code = 1 .lgUsri3_code_page = 1252 . . . End With BEGIN CALLOUT C '* Add the user lgResult = NetUserAdd(btSNArray(0), 3, UserStruct, lgParmError) AddUser = lgResult END CALLOUT C '* More API return value error handling If lgResult = 2224 Then MsgBox "User Already Exists Error", vbOKOnly, "AddUser Error" ElseIf lgResult <> 0 Then MsgBox "Add User Error " & lgResult & " in parameter " & lgParmError _ & " when adding User " & stUName End If '* Release buffers from memory lgResult = NetAPIBufferFree(lgUNPtr) lgResult = NetAPIBufferFree(lgPWDPtr) . . . End Function