Ok, so I have been going at this forever now and I am finding no answers to this that actually work. So, I am trying to create a Script which will make a local user change their password when they next logon. I have looked and looked and looked, but nothing helps. Though I feel like I’m close but missing something. Now I will say I am very, very new to scripting in general so sorry if I seem dumb, but I’d love the help. Also, I am using Windows 10 (not sure if that will make a difference). I am also creating this for a school assignment and I did ask my teacher for a hand, but it’s been a week sense I have heard anything. Thank you!
Now here is what I have:
strComputer = "LAPTOP-56BDJGPQ"
Set usr = GetObject("WinNT://LAPTOP-56BDJGPQ/Guest,user")
usr.Put "PasswordExpired", 1
usr.SetInfo
Now, I know that maybe where it says /Guest,user might be incorrect but I have also tried using my account which is the admin, even that seem to do nothing.
Here is what happens when I run it (now, I do run everything through command prompt)
c:\Comp230>cscript USER_Logon_reset.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
c:\Comp230>
Now this to me shows it ran, but when I go to test to see if it worked well nothing happens.
I will say I have tried other ways of scripting this part like replacing usr.Put to objUser.Put, etc. I would love any input I could get because this is frustrating.
If the Password Never Expires flag is set, you need to delete it first to expire the password.
Try the following instead.
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000 ' 65536
Set usr = GetObject("WinNT://LAPTOP-56BDJGPQ/JohnDoe,user")
currentFlags = usr.Get("UserFlags")
'check if "password never expires" flag is set. if so, remove it
If currentFlags And ADS_UF_DONT_EXPIRE_PASSWD Then
newFlags = currentFlags - ADS_UF_DONT_EXPIRE_PASSWD
'setting new flags
usr.Put "UserFlags", newFlags
End If
usr.Put "PasswordExpired", 1
usr.SetInfo
You may also need to remove the User Cannot Change Password flag if it's set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With