Pages

Friday, October 11, 2013

Check User Account status and Unlock it if it is found Locked

This Simple batch script can be used to check the status of a user account (Domain account also) and if it is found Locked it will unlock it.

Copy and paste the following lines of code in a batch file and save it as Check&UnlockAccount.cmd

@echo off
:A
setlocal enableextensions
set isLocked=Locked
for /f "tokens=1-3 delims= " %%a in ('net user username ^| find "Locked"') do (set myvar=%%c)
rem echo %myvar%
IF "%myvar%"=="%isLocked%" (net user
username ^/active:yes) ELSE (ECHO Account is already Active)
timeout /t 30
Goto A:



All what is needed now is double click this script and it will start doing the check and unlock:

Note: timeout /t 30 means it will check the account every 30 seconds which can be increased or decreased from -1 to 99999 (seconds) -1. (-1 means it is always timed-out and waits for you to press any key);
If this script is needed for checking a Domain Account then replace the command net user username with net user /domain username  and save it. (it is net user /domain and not the actual domainname) (obviously the id invoking this script should have permissions to unlock the user account in question.

Please post for any feedback/comment/suggestion/query

3 comments: