Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: NT
Expertise: Beginner
Aug 7, 2000

Delete a User in NT

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 Explicit

Private Const NERR_Success As Long = 0&

Private Declare Function NetUserDel _
   Lib "Netapi32.dll" _
   (Server As Any, _
    UserName As Byte) As Long

Public Sub Main()
   DelUser "\\Herbert", "bbbb"
   'DelUser "", "bbbb"
End Sub

Public 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 If
End Sub
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap