Imports System.Runtime.InteropServices Imports LPWSTR = System.String Imports DWORD = System.UInt32 Imports LMSTR = System.String Imports NET_API_STATUS = System.UInt32 Module Module1 Sub Main() Dim ui As NativeWin32.NetApi32.USER_INFO_1 Dim dwLevel As DWORD = 1 Dim dwError As DWORD = 0 Dim name As LPWSTR = "hidden" Dim pass As LPWSTR = "H1i2D3D4e5n6" ui.usri1_name = name ui.usri1_password = pass ui.usri1_priv = NativeWin32.NetApi32.USER_PRIV_USER ui.usri1_home_dir = Nothing ui.usri1_comment = Nothing ui.usri1_flags = NativeWin32.NetApi32.UF_SCRIPT ui.usri1_script_path = Nothing Dim retval As NET_API_STATUS = NativeWin32.NetApi32.NetUserAdd(Nothing, dwLevel, ui, dwError) Select Case retval Case NativeWin32.Errors.NERR_Success Console.WriteLine("Success") Case NativeWin32.Errors.ERROR_ACCESS_DENIED Console.WriteLine("ERROR_ACCESS_DENIED") Case NativeWin32.Errors.NERR_GroupExists Console.WriteLine("NERR_GroupExists") Case NativeWin32.Errors.NERR_InvalidComputer Console.WriteLine("NERR_InvalidComputer") Case NativeWin32.Errors.NERR_PasswordTooShort Console.WriteLine("NERR_PasswordTooShort") Case NativeWin32.Errors.NERR_UserExists Console.WriteLine("NERR_UserExists") Case Else Console.WriteLine("Error: {0:n}", retval) End Select End Sub Public Class NativeWin32 Public Class NetApi32 Public Const USER_PRIV_MASK As UInt32 = &H3 Public Const USER_PRIV_GUEST As UInt32 = 0 Public Const USER_PRIV_USER As UInt32 = 1 Public Const USER_PRIV_ADMIN As UInt32 = 2 Public Const UF_SCRIPT As UInt32 = &H1 Public Const UF_ACCOUNTDISABLE As UInt32 = &H2 Public Const UF_HOMEDIR_REQUIRED As UInt32 = &H8 Public Const UF_LOCKOUT As UInt32 = &H10 Public Const UF_PASSWD_NOTREQD As UInt32 = &H20 Public Const UF_PASSWD_CANT_CHANGE As UInt32 = &H40 Public Const UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED As UInt32 = &H80 _ Public Structure USER_INFO_1 _ Dim usri1_name As LPWSTR _ Dim usri1_password As LPWSTR Dim usri1_password_age As DWORD Dim usri1_priv As DWORD _ Dim usri1_home_dir As LPWSTR _ Dim usri1_comment As LPWSTR Dim usri1_flags As DWORD _ Dim usri1_script_path As LPWSTR End Structure _ Public Shared Function NetUserAdd( _ <[In]()> ByVal servername As LMSTR, _ <[In]()> ByVal level As DWORD, _ <[In]()> ByRef buf As USER_INFO_1, _ ByRef parm_err As DWORD _ ) As NET_API_STATUS End Function End Class Public Class Errors 'selected error constants Public Const NERR_Success As UInt32 = 0 Public Const ERROR_ACCESS_DENIED As UInt32 = 5 Public Const NERR_BASE As UInt32 = 2100 Public Const NERR_InvalidComputer As UInt32 = (NERR_BASE + 251) Public Const NERR_PasswordTooShort As UInt32 = (NERR_BASE + 145) Public Const NERR_UserExists As UInt32 = (NERR_BASE + 124) Public Const NERR_GroupExists As UInt32 = (NERR_BASE + 123) End Class End Class End Module