none
VBS Password Change help RRS feed

  • Question

  • I'm trying to change domain users passwords with VBS script. I got it to work with passwords, but now I need it to prompt them to change it when they first log on. I'm not sure what I'm missing.

    strUser = InputBox ("Enter User Name")

    On Error Resume Next

    Set objUser = GetObject("WinNT://domain/" & strUser &", User")

    objUser.SetPassword ("Password")

    objUser.Put "pwdLastSet", 0

    objUser.SetInfo

    If Err.Number <> 0 Then

    MsgBox "Error..."

    Err.Clear

    Else

    MsgBox "The password has been changed for " & strUser &"

    End If

    Wednesday, April 16, 2014 10:10 PM

Answers

All replies

  • You will likely not be able to run this as a logon script.  If you just expire the password the system will prompt.  You can just set the "User must change" flag and the user will be prompted to change the password on logon.

    In Vista and later logon script cannot usually display a UI.  The message boxes do not show.

    You also cannot run On Error the way you are.  It will give you the in correct results.

    Why would you hard code the same password for every users?  This makes no sense.

    Why are you trying to avoid using the correct methods in Windpws to manage a users passwords?


    ¯\_(ツ)_/¯

    Wednesday, April 16, 2014 10:32 PM
  • Appreciate the response. I'm trying to give a helping hand to our techs who work with around a 100 or so users who barely know how to type let alone use a computer (they are learning). That being said, logging into different systems to do this seems to be a hassle and I thought this would streamline the process.

    I did get the password change to work, it's when I added in the expiration to prompt for a change at logon that I cannot figure out. 

    Or if im doing this completely backwards and there's a better way, I'm all ears.

    (...very new to scripting)

    Thursday, April 17, 2014 12:16 PM
  • http://blogs.technet.com/b/heyscriptingguy/archive/2005/07/06/how-can-i-cause-a-user-s-password-to-expire.aspx

    Set objUser = GetObject("LDAP://CN=myerken,OU=Finance,DC=Fabrikam,DC=com")
    
    objUser.pwdLastSet = 0
    objUser.SetInfo
    


    MCP/MCSA/MCTS/MCITP

    Thursday, April 17, 2014 12:28 PM
  • Appreciate the response. I'm trying to give a helping hand to our techs who work with around a 100 or so users who barely know how to type let alone use a computer (they are learning). That being said, logging into different systems to do this seems to be a hassle and I thought this would streamline the process.

    I did get the password change to work, it's when I added in the expiration to prompt for a change at logon that I cannot figure out. 

    Or if im doing this completely backwards and there's a better way, I'm all ears.

    (...very new to scripting)

    Is this in a domain?

    Just set the User must change on the account in AD.  The rest is automatic.  What you are doing is not how we do this.


    ¯\_(ツ)_/¯

    Thursday, April 17, 2014 12:43 PM
  • Thursday, April 17, 2014 12:44 PM
  • Here is the vbscript to do the same.

    strUserID = "userid"
    Set objUser = GetObject("WinNT://DOMAIN/" & strUserID)
    objUser.Put "PasswordExpired", 1
    objUser.SetInfo
    
    
     


    ¯\_(ツ)_/¯


    • Edited by jrv Thursday, April 17, 2014 12:48 PM
    Thursday, April 17, 2014 12:47 PM
  • Thanks, this last bit helped out a lot. I substituted

    objUser.Put "pwdLastSet", 0

    for

    objUser.Put "PasswordExpired", 1

    

    Thursday, April 17, 2014 1:49 PM