1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
Public Const USER_PRIV_USER As UInt32 = 1
Public Const USER_PRIV_ADMIN As UInt32 = 2
Private Sub Btn_Creer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Creer.Click
Dim ErrCreateUser As NET_API_STATUS
ErrCreateUser = CreateUser("MonPC", "utilisateur-admin", "un mot de passe super dur", "Une description", "Nom complet du user", USER_PRIV_ADMIN)
End Sub
Public Shared Function CreateUser(ByVal ServerName As String, ByVal UserName As String, ByVal Password As String, ByVal Description As String, ByVal FullName As String, ByVal Privilege As UInt32) As NET_API_STATUS
Dim ui As NativeWin32.NetApi32.USER_INFO_2
Dim dwLevel As DWORD = 1
Dim dwError As DWORD = 0
ui.full_name = FullName
ui.logon_server = Nothing
ui.param = Nothing
ui.usr_comment = Nothing
ui.workstations = Nothing
ui.name = UserName
ui.password = Password
ui.priv = Privilege
ui.home_dir = Nothing
ui.comment = Description
ui.flags = UF_SCRIPT
ui.script_path = Nothing
Return NetUserAdd(ServerName, dwLevel, ui, dwError)
End Function
<DllImport("Netapi32.dll", CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function NetUserAdd(ByVal ServerName As String, ByVal Level As Integer, <[In]()> ByRef buf As USER_INFO_2, <Out()> ByRef parm_err As DWORD) As NET_API_STATUS
End Function |
Partager