Question:
How do I delete a user in NT with the API’s?
Answer:
The code below shows how to delete a user (if the server name is blank, it attempts to delete a user on the local computer):
Option ExplicitPrivate Const NERR_Success As Long = 0&Private Declare Function NetUserDel _ Lib "Netapi32.dll" _ (Server As Any, _ UserName As Byte) As LongPublic Sub Main() DelUser "\Herbert", "bbbb" 'DelUser "", "bbbb"End SubPublic Sub DelUser(ByVal xi_strServer As String, _ ByVal xi_strUserName As String) Dim p_abytServer() As Byte Dim p_abytUser() As Byte Dim p_lngRtn As Long If Len(Trim$(xi_strServer)) 0 Then p_abytServer = xi_strServer End If If Len(Trim$(xi_strUserName)) = 0 Then MsgBox "You must supply a user name!" Exit Sub Else p_abytUser = xi_strUserName & Chr$(0) If Len(Trim$(xi_strServer)) = 0 Then p_lngRtn = _ NetUserDel(Server:=ByVal Chr$(0), _ UserName:=p_abytUser(0)) Else p_lngRtn = NetUserDel(Server:=p_abytServer(0), _ UserName:=p_abytUser(0)) End If If p_lngRtn = NERR_Success Then MsgBox "Success" Else MsgBox "Could not delete the user, " & _ xi_strUserName & vbCrLf & _ "Error was: " & p_lngRtn End If End IfEnd Sub