If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Problems with NetAddUser

I am working on a project that adds users and groups to a domain. Here is
the problem that I am having. When I execute the program on any machine
other than the Primary Domain Controller, I get a 123 error, which as near
as I can tell, essentially is saying it cannot find the PDC. Also, I get
the same error running the program on the PDC using the pointer to the name.
If I pass in a 0 for the server parameter, it works without a hitch.

Thinking that I wasn't calling it correctly, I incorporated a function that
returns a pointer to the PrimaryDC and used that value to pass into the NetAddUser
API, but still the same 123 error. I am stumped.

Any ideas as to why I cannot run this API would be helpful. I have to believe
that is can be done. Here is the code that I am using.

Thanks
Jeff Morgan

Function AddUser3(ByVal ServerName As String, ByVal uname As String, ByVal
PWD As String, ByVal full_name As String, ByVal Comment As String, ByVal
Group As String) As Long

On Error GoTo AddUserAPI_Err

Dim result As Long
Dim iSuccess As Integer
Dim COMPtr As Long
Dim UNPtr As Long
Dim PWDPtr As Long
Dim SNPtr As Long
Dim FNPtr As Long
Dim GrpPTR As Long
Dim tstPtr As Long
Dim ParmError As Long
Dim SNArray() As Byte
Dim COMArray() As Byte
Dim UNArray() As Byte
Dim PWDArray() As Byte
Dim FNArray() As Byte
Dim GRPArray() As Byte
Dim tstArray() As Byte
Dim sString As String

Public Declare Function NetUserAdd Lib "netapi32" (lpServer As Any, ByVal
level As Long, lpUser As UserInfo3, lpError As Long) As Long

Public Declare Function NetGroupAdd Lib "netapi32.dll" (ServerName As Any,
ByVal level As Long, Buffer As GroupInfo1, ParmError As Long) As Long
Public Declare Function NetGetDCName Lib "netapi32.dll" (ServerName As Long,
DomainName As Byte, DCNPtr As Long) As Long
Public Declare Function NetUserDel Lib "netapi32.dll" (ServerName As Byte,
UserName As Byte) As Long
Public Declare Function NetGroupAddUser Lib "netapi32.dll" (ServerName As
Byte, GroupName As Byte, UserName As Byte) As Long
Public Declare Function NetGroupDelUser Lib "netapi32.dll" (ServerName As
Byte, GroupName As Byte, UserName As Byte) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest
As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Public Declare Function NetAPIBufferFree Lib "netapi32.dll" Alias "NetApiBufferFree"
(ByVal Ptr As Long) As Long
Public Declare Function NetAPIBufferAllocate Lib "netapi32.dll" Alias "NetApiBufferAllocate"
(ByVal ByteCount As Long, Ptr As Long) As Long
Public Declare Function PtrToStr Lib "kernel32" Alias "lstrcpyW" (RetVal
As Byte, ByVal Ptr As Long) As Long
Public Declare Function StrToPtr Lib "kernel32" Alias "lstrcpyW" (ByVal Ptr
As Long, Source As Byte) As Long
Private Declare Sub lstrcpyW Lib "kernel32" (dest As Any, ByVal src As Any)

Public Type UserInfo3
' Level 0 starts here
Name As Long
' Level 1 starts here
Password As Long
PasswordAge As Long
Privilege As Long
HomeDir As Long
Comment As Long
Flags As Long
ScriptPath As Long
' Level 2 starts here
AuthFlags As Long
FullName As Long
UserComment As Long
Parms As Long
Workstations As Long
LastLogon As Long
LastLogoff As Long
AcctExpires As Long
MaxStorage As Long
UnitsPerWeek As Long
LogonHours As Long
BadPwCount As Long
NumLogons As Long
LogonServer As Long
CountryCode As Long
CodePage As Long
' ' Level 3 starts here
UserID As Long
PrimaryGroupID As Long
Profile As Long
HomeDirDrive As Long
PasswordExpired As Long
End Type

Public Type GroupInfo1
GroupName As Long
GroupComment As Long
End Type