VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



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

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

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!

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

'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

Download this snippet    Add to My Saved Code

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

No comments have been posted about Change ANY users / user PASSWORD on the network / lan you are connected to. Why not be the first to post a comment about Change ANY users / user PASSWORD on the network / lan you are connected to.

Post your comment

Subject:
Message:
0/1000 characters