Winscripter
  WSH
  Forums
  Downloads
  Books
  Links
  Amazon




Login
Register

© winscripter.com
1998-2004







Unlock a user account

Posted by on Sunday, June 13, 2004 (PST)

Example of how to unlock a computer account using ADSI. Accounts can be local or domain accounts. Checks the IsAccountLocked property of the IADsUser object (true = Locked).
/*
 * 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 );
}
 

Comments:

re
By mevo on Sunday, June 13, 2004 (PST)

hello Daren!

 

This code is nice. but it is not usefull.

Many admin use AD in 2k and 3k system. you wrote for only local ws or NT srv.  

Reply to this Comment

Should work
By Daren on Tuesday, August 31, 2004 (PST)

Mevo,

I know for a fact it works on Win2K domains, I   It should work the same on Win2k3.  You are probably refering to the "WinNT" and naturally assuming this is for Windows NT only.  This is just a namespace used by ADSI.  There are several such as LDAP, WinNT, etc..

I should mention that the preferred method moving forward is to use LDAP syntax.

Hope it helps,

Daren

Reply to this Comment

Add Your Comment



WSH and ADSI Administrative Scripting

New Articles
  • List installed COM objects and associated ProgIDs
    Script: Lists all COM Objects and their associated ProgIDs (If available). Win32_ClassicCOMClassSetting

  • Script: File Rotator
    Script: Rotate files where the most current file has the lowest number in the archive. When files exceed the retention period, they are deleted. Typically used for log files, backups, etc..

  • Script: Create IIS Website and DNS record
    Script: Dan Casier sent me this script that will create a website and appropriate DNS record. The script is intended for Windows 2000 Server with local DNS and necessary DNS mof installed.


  • Winscripter   |  WSH   |  Forums   |  Downloads   |  Books   |  Links   |  Amazon