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)
<P>hello Daren!</P>
<P>&nbsp;</P>
<P>This code is nice. but&nbsp;it is not usefull. </P>
<P>Many admin use AD&nbsp;in 2k and 3k system. you wrote for only local ws or NT srv.&nbsp;&nbsp;</P>

Should work
By Daren on Tuesday, August 31, 2004 (PST)
<P>Mevo,</P>
<P>I know for a fact it works on Win2K domains, I&nbsp;&nbsp; It should work the same on Win2k3.&nbsp; You are probably refering to the "WinNT" and naturally assuming this is for Windows NT only.&nbsp; This is just a namespace used by ADSI.&nbsp; There are several such as LDAP, WinNT, etc.. </P>
<P>I should mention that the preferred method moving forward is to use LDAP syntax.</P>
<P>Hope it helps,</P>
<P>Daren</P>



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