Subscribe to Windows IT Pro
February 24, 2004 12:00 AM

Unlock User Accounts

Windows IT Pro
InstantDoc ID #41551
Rating: (12)
Downloads
41551.zip

EDITOR'S NOTE: Share your Windows and .NET discoveries, comments, problems, solutions, and experiences with products and reach out to other Windows & .NET Magazine readers (including Microsoft). Email your contributions (400 words or less) to r2r@winnetmag.com. Please include your phone number. We edit submissions for style, grammar, and length. If we print your submission, you'll get $100. Submissions and listings are available online at http://www.winnetmag.com. Enter the InstantDoc ID number in the InstantDoc ID text box.

When I heard that you could delegate Active Directory (AD) tasks, I wondered whether I could use this feature to give departments the ability to unlock user accounts and thereby lighten my Help desk staff's workload. I decided to give unlock rights to several people in each department: the department manager or supervisor, two people who start work early, and two people who work late.

I created an AD group that contained these people and followed the instructions in the Microsoft article "How To Delegate the Unlock Account Right" (http://support.microsoft.com/?kbid=294952) to grant unlock rights to this group. Although my solution worked, the users with unlock rights had to open the Microsoft Management Console (MMC) Active Directory Users and Computers snap-in, click the organizational unit (OU), select the user whose account needed to be unlocked, open the user's properties, and clear the Account is Locked out check box. In an attempt to simplify the task, I added the Active Directory Users and Computers snap-in to a new MMC. I then created a new Taskpad View that showed only the OU containing the users from the target department. I distributed this MMC to the users with unlock rights. This method was easier but still required five or more clicks to unlock a user's account. In addition, this method let the users with unlock rights easily view other users' properties (e.g., account expiration).

To solve the problem, I adapted the MMC I had created. I configured an Unlock User Account button (i.e., task) on the Taskpad View. When you select a user and click the button, the Unlock.vbs script, which Listing 1 shows, runs to unlock the user—whether or not the user was locked out. For tracking reasons, the script also writes an event to one of our servers, noting who unlocked whom and when.

For relevance and simplicity, I also pared down the MMC Taskpad View to contain only three columns: the username, logon name, and object type (i.e., User). I configured the Unlock User Account button to run the Unlock.vbs script, passing the username (i.e., the value in column 0) as arguments.

The script concatenates the username into a Lightweight Directory Access Protocol (LDAP) name (I couldn't easily find the LDAP name to pass as an argument), then sets the LockoutTime attribute to 0. Clearing the LockoutTime attribute unlocks the account.

The script then notes that the user's account is unlocked and records the transaction details in the domain controller's (DC's) event log in which the user is logged on. Because of the nature of delegation, users can unlock only user accounts in their own OUs—except administrator accounts or their own accounts. In my organization, we also let users unlock backup user accounts (e.g., for staff who dial in to check backups).

You need to ensure that the snap-in is secure before you distribute it. Set the correct permissions on the file and script to prevent users from authoring the file or script or changing either's contents.

Department staff, rather than the Help desk staff, can now unlock user accounts. This method is simple and requires just one program and one click.

Related Content:

ARTICLE TOOLS

Comments
  • Ronni
    2 years ago
    Apr 06, 2010

    Alternatey just use this app to unlock accounts. no nonsense app. http://www.nicetool.net/nicetool/adunlockusers.html

  • Roberto Jr.
    7 years ago
    Nov 21, 2005

    ey guys, i thought you might want to consider this script. this unlocks a user whatever OU it is in. you should view PRE WINDOWS 2000 LOGON NAME column and enter "$COL<9>" in the task parameter though.

    Const EVENT_SUCCESS = 0

    If WScript.Arguments.Count = 0 Then
    WScript.Echo "No User Selected"
    WScript.Quit
    End If

    For Each User In WScript.Arguments
    dim userid,UsrObj
    Const domain="gulfunion"
    userid = User
    Set UsrObj = GetObject("WinNT://" & domain & "/" & userid)
    If UsrObj.IsAccountLocked = TRUE Then
    UsrObj.IsAccountLocked = FALSE
    UsrObj.SetInfo
    End If
    wscript.echo "Account " & domain & "\\" & userid & " unlocked."
    next

  • jeremy
    7 years ago
    Nov 03, 2005

    I found it easier to setup the taskpad to show the pre-2000 login name (basically to make it show the samid) and then set the task for a command line option and have it open net with the option (or whatever the second line of it was called) user /domain /active:yes and then get the value for the samid (it is under the arrow on the right).
    The one thing I will say is if you are getting null passed through the script it is cause you dont have that particular columm shown (which is why I needed to tell the taskpad to show the samid)

  • Anonymous User
    7 years ago
    Jul 26, 2005

    I have copied this script and it keeps blowing up on Line 16 Char 1, which is this line.

    set objUser = getObject (ObjLDAPNAME)

    Am I missing something here?
    Any responce would be great.

  • Anonymous User
    7 years ago
    May 31, 2005

    ----------------------
    Rob.

    What may have been missing from the article was that the parameters for running the script in the taskpad view should be as below - including punctuation.

    "$COL<0>"

    This will pass the contents of Column 0 to the script. Good Luck!
    ----------------------

    This works as I did this and had no problems, just REM out the first line of the vbscript, modify your LDAP info and make sure you use the info provided above.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.