When working in a corporate Windows domain environment, standard users often need to change their passwords regularly due to security policies. While the graphical CTRL+ALT+DEL method works, automation becomes essential for efficiency.
The typical net user
approach fails because:
net user myaccount * /domain
System error 5 has occurred.
Access is denied.
This occurs because password changes through net user
require Domain Admin privileges, while the secure desktop method uses a different authentication path.
For Windows 7/10/11 systems with PowerShell access:
$secureString = ConvertTo-SecureString "NewP@ssw0rd123!" -AsPlainText -Force
Set-ADAccountPassword -Identity $env:USERNAME -NewPassword $secureString -OldPassword (Read-Host "Enter current password" -AsSecureString) -Server "your.domain.controller"
Create a file named changepwd.vbs
:
Set objUser = GetObject("WinNT://DOMAIN/" & WScript.Arguments(0))
objUser.ChangePassword WScript.Arguments(1), WScript.Arguments(2)
WScript.Echo "Password changed successfully"
Run with:
cscript changepwd.vbs username currentpass newpass
Compile this C# code into an executable:
using System;
using System.DirectoryServices;
class PasswordChanger {
static void Main(string[] args) {
try {
DirectoryEntry user = new DirectoryEntry(
"WinNT://DOMAIN/" + args[0],
args[0],
args[1]);
user.Invoke("ChangePassword", args[1], args[2]);
Console.WriteLine("Password changed successfully");
} catch (Exception ex) {
Console.WriteLine("Error: " + ex.Message);
}
}
}
- Never store passwords in plaintext scripts
- Use proper error handling to avoid exposing sensitive information
- Consider password policy requirements (complexity, history, etc.)
For the specific case of cycling through 24 passwords, create a batch file that:
@echo off
for /L %%i in (1,1,24) do (
cscript changepwd.vbs %USERNAME% password%%i password%%i+1
timeout /t 5
)
Error | Solution |
---|---|
0x8007005 (Access Denied) | Check if password change rights are delegated |
0x80070056 (Invalid Password) | Verify current password correctness |
0x800708C5 (Policy Restriction) | Ensure new password meets complexity requirements |
When working in a locked-down Windows domain environment (especially on legacy systems like Windows XP SP3), standard password change methods often require domain admin privileges. The classic net user
approach fails with "Access is denied" for regular users, while the GUI method (Ctrl+Alt+Del → Change Password) works but can't be automated.
Many developers face this exact scenario:
- Frequent password rotation policies (e.g., every 14 days)
- Password history requirements (e.g., no reuse of last 24 passwords)
- The need to automate repetitive credential cycles
For modern systems, we'd use:
$newPass = ConvertTo-SecureString "NewP@ssw0rd" -AsPlainText -Force
Set-ADAccountPassword -Identity $env:USERNAME -NewPassword $newPass -Server DomainController -OldPassword (Read-Host "Current password" -AsSecureString)
For our legacy XP scenario, we'll need to use the Windows API via VBScript:
Set objUser = GetObject("WinNT://DOMAIN/" & WScript.Arguments(0))
objUser.ChangePassword WScript.Arguments(1), WScript.Arguments(2)
WScript.Echo "Password changed successfully"
Save as changepw.vbs
and run:
cscript changepw.vbs username oldpass newpass
For more complex scenarios (like cycling through 24 passwords):
#include
Send("^!{DEL}") ; Ctrl+Alt+Del
WinWait("Windows Security")
ControlClick("Windows Security", "", "Button2") ; Change Password
WinWait("Change Password")
ControlSetText("Change Password", "", "Edit1", $oldPass)
ControlSetText("Change Password", "", "Edit2", $newPass)
ControlSetText("Change Password", "", "Edit3", $newPass)
ControlClick("Change Password", "", "Button1") ; OK
While automating password changes solves the immediate problem:
- Never store plaintext passwords in scripts
- Consider using enterprise password managers instead
- For XP systems especially, ensure scripts are deleted after use
As a last resort, you can modify the Stored User Names and Passwords vault:
reg add "HKCU\Software\Microsoft\Protected Storage System Provider" /f
reg add "HKCU\Software\Microsoft\Protected Storage System Provider\" /f
reg add "HKCU\Software\Microsoft\Protected Storage System Provider\\Preferred" /v "DPAPI_CURRENT_PASSWORD" /t REG_BINARY /d /f