;; 
;;=====================================================================================----- 
;;FUNCTION      ADSIUserStatus() 
;; 
;;ACTION        Returns the status of a user account 
;; 
;;AUTHOR        Jens Meyer 
;; 
;;VERSION       1.0 - 2004/03/14 
;; 
;;SYNTAX        ADSIUserStatus(UserName [, Opt, DOMAIN]) 
;; 
;;PARAMETERS    USERNAME 
;;              Required string containing the username 
;; 
;;              OPT - Optional 
;;              Integer containing: 
;;              0 = return account status (default) 
;;              1 = unlock user account 
;;              2 = enable user account 
;;              3 = disable user account 
;; 
;;              DOMAIN -Optional 
;;              String containing the domain or local computer  
;;              name the user is a member of 
;; 
;;RETURNS       Int - 0=Enabled, 1=Locked, 2=Disabled 
;; 
;;REMARKS       Requires WMI and the account the script runs under must be 
;;              a member of the 'Account Operators' group when changing the 
;;              account status. It is not recommended to unlock a user 
;;              account via the LDAP provider, instead the WinNT should be used. 
;;              See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/ldap_account_lockout.asp 
;; 
;;DEPENDENCIES  none 
;; 
;;EXAMPLES       SELECT 
;;              CASE ADSIUserStatus('lockeduser')=1 
;;                $rc=ADSIUserStatus('lockeduser',1) 
;;              CASE ADSIUserStatus('lockeduser')=2 
;;                $rc=ADSIUserStatus('lockeduser',2) 
;;              ENDSELECT 
;;              $rc=ADSIUserStatus('lockeduser',0,'domain') 
;;              $rc=ADSIUserStatus('lockeduser',0,'computer') 
;;              $rc=ADSIUserStatus('CN=Jeff Smith,OU=Sales,DC=Fabrikam,DC=Com',0) 
;; 
;;KIXTART BBS   http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=114912 
; 
function ADSIUserStatus($user, optional $opt, optional $domain)
 
  dim $objUser, $strProvider
 
  $user=trim($user)
  $domain=trim($domain)
  $opt=val($opt)
  if $user='' or (instr($user,'/') and $domain) or (instr($user,'CN=') and $opt=1)
    exit 87
  endif
 
  select
  case instr($domain,'CN=')
    $strProvider='LDAP://'+$user
  case $domain
    $strProvider='WinNT://'+$domain+'/'+$user+',user'
  case 1
    $strProvider='WinNT://'+@DOMAIN+'/'+$user+',user'
  endselect
 
  $objUser = getobject($strProvider)
 
  if @ERROR
    exit @ERROR
  endif
 
  select
    case $opt=1
      if $objUser.IsAccountLocked
        $objUser.IsAccountLocked=0
        $objUser.SetInfo
      endif
    case $opt=2
      if $objUser.AccountDisabled
        $objUser.AccountDisabled=0
        $objUser.IsAccountLocked=0
        $objUser.SetInfo
      endif
    case $opt=3
      if not $objUser.AccountDisabled
        $objUser.AccountDisabled=1
        $objUser.SetInfo
      endif
  endselect
 
  select
  case $objUser.AccountDisabled
    $ADSIUserStatus=2
  case $objUser.IsAccountLocked
    $ADSIUserStatus=1
  case 1
    $ADSIUserStatus=0
  endselect
 
  $objUser = 0
 
endfunction