Click to See Complete Forum and Search --> : NetUserAdd


CecileR
July 3rd, 2001, 07:31 AM
Anyone knows how will I correct this

I add this to my code

Private Declare Function NetUserAdd Lib "NetApi32" (servername AS Byte,_
ByVal level As Long,
buff As Long,
parm_err As Long) As Long

Private Type USER_INFO_4
usr1_name As Long
usr1_password As Long
usr1_password_age As Long
usr1_priv As Long
usr1_home_dir As Long
usr1_comment As Long
usr1_flags As Long
usr1_script_path As Long
End Type

But I dont know how to pass this structure to the api function since it only accepts "Long":

NetUserAdd(ServerName(0),1,?,parm_err)

Somebody knows about this api? Please help me
by having sample code or use.

cecile

The more u read, the more u do not know

cksiow
July 3rd, 2001, 08:23 AM
try

Private Declare Function NetUserAdd Lib "NetApi32" (servername AS Byte,_
ByVal level As Long,
buff As any,
parm_err As Long) As Long




HTH

cksiow
http://vblib.virtualave.net - share our codes

CecileR
July 3rd, 2001, 09:15 PM
Still it doesn't run:
Here is my code,

Private Type USER_INFO_4
usr1_name As String
usr1_password As String
usr1_password_age As Long
usr1_priv As Long
usr1_home_dir As Long
usr1_comment As Long
usr1_flags As Long
usr1_script_path As Long
End Type

Private Sub Form_Load()
Dim tmp As String

tmp = funcGetComputerName
Label6.Caption = tmp
If Len(tmp) > 0 Then
If InStr(tmp, "\\") > 0 Then
bServerName = tmp & Chr$(0)
Else
bServerName = "\\" & tmp & Chr$(0)
End If
End If

End Sub

Private Function funcGetComputerName() As String
Dim tmp As String

'buffer
tmp = Space$(MAX_COMPUTERNAME + 1)
If GetComputerName(tmp, Len(tmp)) <> 0 Then
funcGetComputerName = TrimNull(tmp)
End If

End Function
Private Function TrimNull(str As String) As String
Dim pos

pos = InStr(str, Chr$(0))

If pos > 0 Then
TrimNull = Left$(str, pos - 1)
Else
TrimNull = str
End If
End Function

Private Sub Command1_Click()
Dim parm_err As Long
Dim usrapi As USER_INFO_4
Dim h As Long

usrapi.usr1_name = "Sony"
usrapi.usr1_password = ""
usrapi.usr1_comment = 0
usrapi.usr1_flags = 0
usrapi.usr1_home_dir = 0
usrapi.usr1_password_age = 0
usrapi.usr1_priv = USER_PRIV
usrapi.usr1_script_path = UF_SCRIPT

' h = NetUserAdd(bServerName(0), 1, usrapi, 0&)
If NetUserAdd(bServerName(0), 1, usrapi, 0&) = ERROR_SUCCESS Then
Label6.Caption = "Nothing"
Label6.Refresh
End If

End Sub
Private Declare Function NetUserAdd Lib "Netapi32" _
(servername As Byte, _
ByVal level As Long, _
buff As Any, _
parm_err As Long) As Long

The more u read, the more u do not know

cksiow
July 3rd, 2001, 09:41 PM
this is the C declaration for the structure, are you sure you convert it to VB correctly ?

typedef struct _USER_INFO_4 {
LPWSTR usri4_name;
LPWSTR usri4_password;
DWORD usri4_password_age;
DWORD usri4_priv;
LPWSTR usri4_home_dir;
LPWSTR usri4_comment;
DWORD usri4_flags;
LPWSTR usri4_script_path;
DWORD usri4_auth_flags;
LPWSTR usri4_full_name;
LPWSTR usri4_usr_comment;
LPWSTR usri4_parms;
LPWSTR usri4_workstations;
DWORD usri4_last_logon;
DWORD usri4_last_logoff;
DWORD usri4_acct_expires;
DWORD usri4_max_storage;
DWORD usri4_units_per_week;
PBYTE usri4_logon_hours;
DWORD usri4_bad_pw_count;
DWORD usri4_num_logons;
LPWSTR usri4_logon_server;
DWORD usri4_country_code;
DWORD usri4_code_page;
PSID usri4_user_sid;
DWORD usri4_primary_group_id;
LPWSTR usri4_profile;
LPWSTR usri4_home_dir_drive;
DWORD usri4_password_expired;
}USER_INFO_4, *PUSER_INFO_4, *LPUSER_INFO_4;




HTH

cksiow
http://vblib.virtualave.net - share our codes

CecileR
July 3rd, 2001, 09:48 PM
I tried to use USER_INFO_1

But it doesn't work. :( again

The more u read, the more u do not know

CecileR
July 3rd, 2001, 10:18 PM
see this one.. Why it isn't running?

Private Type USER_INFO_1
usr1_name As String
usr1_password As String
usr1_password_age As Double
usr1_priv As Double
usr1_home_dir As String
usr1_comment As String
usr1_flags As Double
usr1_script_path As String
End Type

Private Const ERROR_SUCCESS As Long = 0&
Private Const MAX_COMPUTERNAME As Long = 15 'that's constant
Private Const MAX_USERNAME As Long = 256
Private Const FILTER_NORMAL_ACCOUNT As Long = &H2
Private Const USER_PRIV As Long = 1
Private Const UF_SCRIPT As Long = &H1

Private Declare Function NetUserAdd Lib "Netapi32" _
(servername As String, _
ByVal level As Long, _
buff As Any, _
parm_err As Long) As Long

Private Declare Function NetUserGetInfo Lib "Netapi32" _
(lpServer As Byte, _
username As Byte, _
ByVal level As Long, _
lpBuffer As Long) As Long

Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(xDest As Any, _
xSource As Any, _
ByVal nBytes As Long)

Private Declare Function lstrlenW Lib "kernel32" _
(ByVal lpString As Long) As Long

Private Declare Function StrLen Lib "kernel32" _
Alias "lstrlenW" _
(ByVal lpString As Long) As Long
'Adding user to NT account
Private Sub Command1_Click()
Dim parm_err As Long
Dim usrapi As USER_INFO_1
Dim h As Double
Dim c As String
h = 1
c = "Sony"
usrapi.usr1_name = StrConv(c, vbUnicode)
usrapi.usr1_password = StrConv("", vbUnicode)
usrapi.usr1_password_age = 0
usrapi.usr1_comment = StrConv("", vbUnicode)
usrapi.usr1_flags = UF_SCRIPT
usrapi.usr1_home_dir = StrConv("", vbUnicode)
usrapi.usr1_priv = USER_PRIV
usrapi.usr1_script_path = StrConv("", vbUnicode)

' h = NetUserAdd(bServerName(0), 1, usrapi, 0&)
If NetUserAdd("\\" & "ET_WAPSERVER" & Chr$(0), h, usrapi, 0&) = ERROR_SUCCESS Then
Label6.Caption = "Nothing"
Label6.Refresh
End If

End Sub
'End Session
Private Sub Command3_Click()
End
End Sub

Private Sub Form_Load()
Dim tmp As String

tmp = funcGetComputerName
Label6.Caption = tmp
If Len(tmp) > 0 Then
If InStr(tmp, "\\") > 0 Then
bServerName = tmp & Chr$(0)
Else
bServerName = "\\" & tmp & Chr$(0)
End If
End If

End Sub

Private Function funcGetComputerName() As String
Dim tmp As String

'buffer
tmp = Space$(MAX_COMPUTERNAME + 1)
If GetComputerName(tmp, Len(tmp)) <> 0 Then
funcGetComputerName = TrimNull(tmp)
End If

End Function
Private Function TrimNull(str As String) As String
Dim pos

pos = InStr(str, Chr$(0))

If pos > 0 Then
TrimNull = Left$(str, pos - 1)
Else
TrimNull = str
End If
End Function


The more u read, the more u do not know