[vbscript] change (NOT RESET!) passwords at the cmd line

Discussion in 'Scripting' started by bear_aussie, Dec 22, 2017.

  1. bear_aussie

    bear_aussie MDL Junior Member

    Jun 8, 2015
    56
    27
    0
    #1 bear_aussie, Dec 22, 2017
    Last edited: Dec 22, 2017
    my first thread, yay me :)

    anyway, type "change password at the command line" into your favourite search engine. lots of results yeah? all of them saying "net user <username> <newpassword>"

    what they don't tell you is that youre not CHANGING your password, youre RESETING your password - same thing as using lusrmgr.msc - with all the nasty sideeffects of that. it also requires admin privs even to change your OWN password (see https://technet.microsoft.com/en-us/library/cc771690(v=ws.11).aspx for details)

    so im like "screw that" and went for a walk through the guts of windows. couple of hours later I had this vbscript:

    Code:
    ' change these
    username = "bear_aussie"
    oldpass = "0ldP@ssw0rd"
    newpass = "n00p455WorD"
    
    ' do the work
    set user = getobject("WinNT://./" & username & ",user")
    on error resume next
    call user.changepassword(oldpass, newpass)
    if err.number = 0 then
        wscript.echo "success!"
    else
        wscript.echo "failed! error code: " & hex(err.number)
    end if
    afaict, this script does the same thing as changing your pw from winlogon (ctrl+alt+del menu) - correct me if im wrong

    enjoy peeps :D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    5,721
    13,164
    180
    Interesting could you list and elaborate some please?
     
  3. bear_aussie

    bear_aussie MDL Junior Member

    Jun 8, 2015
    56
    27
    0
    see "additional considerations" in the m$ link supplied (third bullet is the most important): iirc doing a password reset kills all your lsa secrets, that's why it brakes stored passwords, efs, etc
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...