Sign in to follow this  
Followers 0
exodius

Unlocking local account

8 posts in this topic

Anyone know of a way with AutoIt to unlock a local admin account (assuming that you yourself have admin privleges) without doing it the manual way (through the control panel)?

Share this post


Link to post
Share on other sites



I doubt any program has access to that. I cannot see why Microsoft would allow that. It could be very dangerous.

Share this post


Link to post
Share on other sites

Anyone know of a way with AutoIt to unlock a local admin account (assuming that you yourself have admin privleges) without doing it the manual way (through the control panel)?

$oMyError = ObjEvent("AutoIt.Error", "ComError")
; Get Admin UserID
$objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//"  & @ComputerName & "/root/cimv2")
$oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount WHERE Domain = '" & @ComputerName & "'")
For $oUserAccount In $oUserAccounts
    If StringLeft($oUserAccount.SID, 9) = "S-1-5-21-" And _
        StringRight($oUserAccount.SID, 4) = "-500" Then
        ExitLoop
    Endif
Next
; Check disabled
ConsoleWrite('Administrator account:' & $oUserAccount.Name & @lf )
Local $objNetwork = ObjCreate("Wscript.Network")
$objUser = ObjGet("WinNT://" & @ComputerName & "/" & $oUserAccount.Name & ",user")
If $objUser.AccountDisabled Then 
    $objUser.AccountDisabled=0
    $objUser.SetInfo
    ConsoleWrite("Admin account enabled" & @lf)
EndIf
;
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
        ConSoleWrite("Com Error:" & $HexNumber)
        ConSoleWrite("  ,Line:" & $oMyError.scriptline)
        ConSoleWrite("  ,LastDllErrc:" & $oMyError.lastdllerror)
        ConSoleWrite("  ,Desc:" & $oMyError.description)
        ConSoleWrite("  ,WinDesc:" & $oMyError.windescription)
        ConSoleWrite(@CRLF)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc   ;==>ComError

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I doubt any program has access to that. I cannot see why Microsoft would allow that. It could be very dangerous.

Don't understand why that would be... When you have admin rights to the BOX then you should be able to do anything .... :lmao: Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

$oMyError = ObjEvent("AutoIt.Error", "ComError")
; Get Admin UserID
$objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//"  & @ComputerName & "/root/cimv2")
$oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount WHERE Domain = '" & @ComputerName & "'")
For $oUserAccount In $oUserAccounts
    If StringLeft($oUserAccount.SID, 9) = "S-1-5-21-" And _
        StringRight($oUserAccount.SID, 4) = "-500" Then
        ExitLoop
    Endif
Next
; Check disabled
ConsoleWrite('Administrator account:' & $oUserAccount.Name & @lf )
Local $objNetwork = ObjCreate("Wscript.Network")
$objUser = ObjGet("WinNT://" & @ComputerName & "/" & $oUserAccount.Name & ",user")
If $objUser.AccountDisabled Then 
    $objUser.AccountDisabled=0
    $objUser.SetInfo
    ConsoleWrite("Admin account enabled" & @lf)
EndIf
; Check if locked 
If $objUser.IsAccountLocked Then 
    $objUser.IsAccountLocked=0
    $objUser.SetInfo
    ConsoleWrite("Admin account unlocked" & @lf)
EndIf
;
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
        ConSoleWrite("Com Error:" & $HexNumber)
        ConSoleWrite("  ,Line:" & $oMyError.scriptline)
        ConSoleWrite("  ,LastDllErrc:" & $oMyError.lastdllerror)
        ConSoleWrite("  ,Desc:" & $oMyError.description)
        ConSoleWrite("  ,WinDesc:" & $oMyError.windescription)
        ConSoleWrite(@CRLF)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc   ;==>ComError
Thanks for the reply JdeB, that works if the account is disabled, how about if the account is enabled but is simply locked out from trying it too many times? Edited by JdeB

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks for the reply JdeB, that works if the account is disabled, how about if the account is enabled but is simply locked out from trying it too many times?

Untested but should be close:

If $objUser.IsAccountLocked Then 
    $objUser.IsAccountLocked=0
    $objUser.SetInfo
    ConsoleWrite("Admin account unlocked" & @lf)
EndIf
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Untested but should be close:

If $objUser.IsAccountLocked Then 
    $objUser.IsAccountLocked=0
    $objUser.SetInfo
    ConsoleWrite("Admin account unlocked" & @lf)
EndIf
That's so awesome JdeB, I tried changing your first post to something similar but I guess I didn't have it right. Thanks!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

That's so awesome JdeB, I tried changing your first post to something similar but I guess I didn't have it right. Thanks!

YW.. updated the first post with the addition...

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0