Always Unlock a Specified Account

email me

This is a simple but effective way to unlock a user account automatically. Note, you cannot use the same account name in the script…to run the script.

I have disabled the message boxes and added a loop.

On Error Resume Next

strUser = "TheUserName"

If strUser = vbNullString then
'MsgBox "Either Cancel was selected or you did not enter a user name.", 16, "User Unlock"
WScript.Quit
End If

strDomain = "YourDomainName"

Set objUser = GetObject("WinNT://"& strDomain &"/" & strUser & "")
If Err.Number <> 0 Then
'MsgBox (strUser) & " isn't a valid user name!", 48,"User Unlock"
Wscript.Quit
End If

Err.Clear

x = 0
do while x = 0

If objUser.IsAccountLocked = 0 Then
'MsgBox (strUser) & " isn't locked out.",64,"User Unlock"
Else
objUser.IsAccountLocked = 0
objUser.SetInfo
If Err.number = 0 Then
'MsgBox (strUser) & " has been unlocked.",64,"Unlock User"
Else
'MsgBox "There was an error unlocking" & (strUser) & " on " & UCase(strDomain) & ".",16,"User Unlock"
End If
End If

wscript.sleep 480000'8 minutes 'waits 8 minutes, and then cycles back. You can change this value.
loop

Set objUser = Nothing
Wscript.Quit