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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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
Thanks for your registration, follow us on our social networks to keep up-to-date