VB icon

Change ANY users / user PASSWORD on the network / lan you are connected to

Email
Submitted on: 1/21/2015 10:50:00 PM
By: Jon Barker (from psc cd)  
Level: Intermediate
User Rating: By 7 Users
Compatibility: VB 5.0, VB 6.0
Views: 758
 
     This code, using the windows API (NetUserChangePassword) call can change any users password on the network you are on, provided you know their original password. You need to know: 1. The machine name (ie. \\jon) 2. The username (NOT case sensitive) (ie. the_cleaner) 3. The old password (ie. password) 4. the new password (ie. password2) Enjoy!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Change ANY users / user PASSWORD on the network / lan you are connected to
' Description:This code, using the windows API (NetUserChangePassword) call can change any users password on the network you are on, provided you know their original password. You need to know: 
1. The machine name (ie. \\jon)
2. The username (NOT case sensitive) (ie. the_cleaner)
3. The old password (ie. password)
4. the new password (ie. password2)
Enjoy!
' By: Jon Barker (from psc cd)
'**************************************

'PASTE THE FOLLOWING INTO ANY FORM...
'YOU MUST HAVE A COMMAND BUTTON
'NAMED 'COMMAND1'
Option Explicit
Private Declare Function NetUserChangePassword Lib "netapi32.dll" ( _
ByVal domainname As String, ByVal Username As String, _
ByVal OldPassword As String, ByVal NewPassword As String) As Long
Private Sub Command1_Click()
On Error GoTo error
Dim r As Long
Dim sServer As String
Dim sUser As String
Dim sOldPass As String
Dim sNewPass As String
sServer = StrConv("\\jon", vbUnicode)
sUser = StrConv("the_cleaner", vbUnicode)
sOldPass = StrConv("password", vbUnicode)
sNewPass = StrConv("password2", vbUnicode)
r = NetUserChangePassword(sServer, sUser, sOldPass, sNewPass)
If r <> 0 Then
MsgBox "Error! Could not change password. Ensure that: " & vbCrLf & vbCrLf & _
"o Old password was correct (Error 86)" & vbCrLf & _
"o The server name started with '\\' (Error 1351)", vbCritical, "Error: " & r
Else
MsgBox "Password changed successfully!", vbExclamation, "Changed Password"
End If
Exit Sub
error:
MsgBox "External error changing password: " & 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.