VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



DELETE a user from ANY COMPUTER on the network

by Jon Barker (11 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

Simple API call to delete any user account on the network. I think you need to be admin to do so... infact, its very likely you have to be :)
You need to know:
1. Machine name (ie. \\jon) 2. Username (ie. the_cleaner)
Enjoy! :)

Rate DELETE a user from ANY COMPUTER on the network

'PASTE THE FOLLOWING INTO A FORM
'YOU NEED A COMMAND BUTTON NAMED
'COMMAND1
Option Explicit
Private Declare Function NetUserDel Lib "NETAPI32.DLL" (ByVal servername As String, ByVal userName As String) As Long

Private Sub Command1_Click()
  On Error GoTo error
  
  Dim r As Long
  Dim sServer As String
  Dim sUser As String

  sServer = StrConv("\\jon", vbUnicode) ' CHANGE THESE TO YOUR SELECTED USER AND SERVER
  sUser = StrConv("the_cleaner", vbUnicode)   ' CHANGE THESE TO YOUR SELECTED USER AND SERVER

  r = NetUserDel(sServer, sUser)
  If r <> 0 Then
    MsgBox "Delete user failed. Ensure: " & vbCrLf & vbCrLf & _
        "o The server name was correct and started with '\\'" & _
        "o You have admin rights for that server (I think :)" & _
        "o The username you specified was valid", vbCritical, "Error: " & r
  Else
    MsgBox "User deleted!", vbExclamation, "Success"
  End If
  Exit Sub
  
error:
  MsgBox "External error deleteing user: " & vbCrLf & vbCrLf & Err.Description, vbCritical, "Error: " & Err.Number
End Sub

Download this snippet    Add to My Saved Code

DELETE a user from ANY COMPUTER on the network Comments

No comments have been posted about DELETE a user from ANY COMPUTER on the network. Why not be the first to post a comment about DELETE a user from ANY COMPUTER on the network.

Post your comment

Subject:
Message:
0/1000 characters