DOWNLOAD THE CODE:
Download the Code 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.

End of Article




You must log on before posting a comment.

If you don't have a username & password, please register now.

Reader Comments

Sweet! This is exactly why I stopped the process to allow users to unlock user accounts. Too many mouse-clicks. I have no Taskpad or VB Script skills, so this will really help. Thanks Padraic.

David Perry

This article sounds great. Is there an article on how to create a Taskpad View and then how to assign the VB script to it. Thanks

Keven Denton

The script is written to handle multiple users, but it doesn't work that way for me. The script runs fine with only one user selected, but not with multiple users. On Windows 2000 with MMC 1.2, nothing happens when I click the Task icon. On Windows XP with MMC 2.0, the Task icon disappears completely so that I can't even click it.

Lee Gray

For some reason when I try to run it, I get an error. Am I doing something wrong? The is as follows: Script: c:\docs and settings\hd\admin tools\unlock.vbs Line: 1 Char: 1 Error: Type mismatch: "Listing' Code: 800A000D Source: Microsoft VBScript runtime error

Can you please guide me back on track?

Thanks! Best Regards,

Rob Spilman

Ok, I fixed my script error. User error on my part. Now everytime I highlight a user in taskpad view and then click the unlock.vbs button, it always says no user selected. Little help please.

Rob Spilman

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!

Padraic

This script is going to be great, but I also having the same problem as Rob, I am always getting a no user selected error from the if/end if test. Thanks

Jeff Waters

When I click the Icon I get - an error of - A referral was returned from the server - it references the line for my OU and domain structure. Any idea what would cause that?

Troy Cosson

What is This ? How is it supposed to work? Now I can see why this magazine plumets every month. Bring back the good people.

Gilles

I am getting the error "Windows Script Host, Script: C:\41551\unlock.vbs, Line:13, Char:1, Error: A referal was returned from the server. Code: 8007202B, source: null

Todd

The problem with this is that the script gets two arguments. The FIRSTNAME and then the LASTNAME. In the FOR EACH User it attempts to set the LockOutTime to 0 on LDAP://CN= FIRSTNAME,OU=Users,DC=Test,DC=com then to LDAP://CN= LASTNAME,OU=Users,DC=Test,DC=com

If there is a way to concatenate the two arguments with a space in the middle that would be work I think.

The way I figured it out was just to put an “WScript.Echo objLDAPNAME” right before the “set objUser = GetObject (objLDAPNAME)”

I am no programmer but I think I am right about this one.

James

Hmmm, can anyone clear this up in a step by step this would be awesome to have.

Todd

Still get 'No User Selected'. I am not sure if I set domain name correct, our domain is ubht.nhs.uk, and i set the objLastPart = dc=ubht,dc=nhs,dc=uk. Is that correct?

Millsy

Todd you mite want to try objLastPart = ",DC=ubht,DC=nhs,DC=uk"

Bret

In reference to James post on March 30. I found that if you put $COL<0> in quotes like he stated i have gotten it to work somewhat. I guess we should have read it verbatem. The only that doesn't work is the part of "no user was selected"

Andy

See More Comments  1   2 
 
 

ADS BY GOOGLE