VB icon

DELETE a user from ANY COMPUTER on the network

Email
Submitted on: 1/21/2015 10:51:00 PM
By: Jon Barker (from psc cd)  
Level: Intermediate
User Rating: By 2 Users
Compatibility: VB 5.0, VB 6.0
Views: 679
 
     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! :)
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: DELETE a user from ANY COMPUTER on the network
' Description: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! :)
' By: Jon Barker (from psc cd)
'**************************************

'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


Other 10 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.