d

Unlock a User Account

Example of how to unlock a user account using ADSI

Accounts can be local or domain. Checks to see if the IsAccountLocked property of IADsUser object (true = locked).

Note: The "WinNT" is a 'namespace' and does not mean it only works on Windows NT.

/*
 * Script:   UnlockAccount.js
 * Purpose:  Unlock user account domain or local.
 * Author:   Daren Thiel
 * Date:     13 June 2004
 * Web:      http://www.winscripter.com
 *
 */ 


UnlockAccount( "yourdomain", "jsmith" );
// Unlock account using ADSI.
//
// Domain: Is the domain where the account resides, computer
// or domain accounts.  For account local to a machine use
// the computer's netbios name. For domain accounts, use
// the domain name.
// 
// Account: Is the account name to be unlocked.
//
function UnlockAccount( domain, account )
{
 try
 {
  var user = GetObject( "WinNT://" + domain + "/" + account );
  if( user.IsAccountLocked )
  {
   user.IsAccountLocked = false;
   user.SetInfo();
   print( "Account Unlocked" );
  }
  else
  {
   print( "Account was not locked" );
  }
 }
 catch( e )
 {
  print( "Error: " + e.description );
 }
}
function print( msg )
{
 WScript.Echo( msg );
}