Sign in to follow this  
Followers 0
NinjaGeek

DirectoryEntry.Exists method

3 posts in this topic

I'm a dabbler when it comes to DLL or COM calls, so I'm not entirely sure how to implement this. I'm trying to use the DirectoryEntry.Exists method to check to see if a username exists on the domain, but I'm not sure where to even start. The method I'm referring to can be found here: http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.exists.aspx

Thanks in advance!

Share this post


Link to post
Share on other sites



I'm a dabbler when it comes to DLL or COM calls, so I'm not entirely sure how to implement this. I'm trying to use the DirectoryEntry.Exists method to check to see if a username exists on the domain, but I'm not sure where to even start. The method I'm referring to can be found here: http://msdn.microsoft.com/en-us/library/...ctoryservices.directoryentry.exists.aspx

Thanks in advance!

Alternatively you can get Domain's Users like this with this Jarvis script :

#include <Array.au3>
Global $Users

$_ComputerUsers = _ComputerGetUsers($Users)
_ArrayDisplay ( $_ComputerUsers )

For $i = 1 To $Users[0][0] Step 1
    MsgBox(0, "Test _ComputerGetUsers", "Name: " & $Users[$i][0] & @CRLF & _
                                        "Domain: " & $Users[$i][1] & @CRLF & _
                                        "Status: " & $Users[$i][2] & @CRLF & _
                                        "Local Account: " & $Users[$i][3] & @CRLF & _
                                        "SID: " & $Users[$i][4] & @CRLF & _
                                        "SIDType: " & $Users[$i][5] & @CRLF & _
                                        "Description: " & $Users[$i][6] & @CRLF & _
                                        "Full Name: " & $Users[$i][7] & @CRLF & _
                                        "Disabled: " & $Users[$i][8] & @CRLF & _
                                        "Lockout: " & $Users[$i][9] & @CRLF & _
                                        "Password Changeable: " & $Users[$i][10] & @CRLF & _
                                        "Password Expires: " & $Users[$i][11] & @CRLF & _
                                        "Password Required: " & $Users[$i][12] & @CRLF & _
                                        "Account Type: " & $Users[$i][13])
Next

;===============================================================================
; Description:      Returns the Users and information in an array.
; Parameter(s):     $aUserInfo - By Reference - User Name and Information array.
; Requirement(s):   None
; Return Value(s):  On Success - Returns array of User Information.
;                  $aUserInfo[0][0]   = Number of Users
;                  $aUserInfo[$i][0]  = Name ($i starts at 1)
;                  $aUserInfo[$i][1]  = Doamin
;                  $aUserInfo[$i][2]  = Status
;                  $aUserInfo[$i][3]  = Local Account
;                  $aUserInfo[$i][4]  = SID
;                  $aUserInfo[$i][5]  = SIDType
;                  $aUserInfo[$i][6]  = Description
;                  $aUserInfo[$i][7]  = Full Name
;                  $aUserInfo[$i][8]  = Disabled
;                  $aUserInfo[$i][9]  = Lockout
;                  $aUserInfo[$i][10] = Password Changeable
;                  $aUserInfo[$i][11] = Password Expires
;                  $aUserInfo[$i][12] = Password Required
;                  $aUserInfo[$i][13] = Account Type
;                   On Failure - @error = 1 and Returns 0
;                        @extended = 1 - Array contains no information
;                                 2 - $colItems isnt an object
; Author(s):        Jarvis Stubblefield (support "at" vortexrevolutions "dot" com)
; Note(s):
;===============================================================================
Func _ComputerGetUsers(ByRef $aUserInfo)
    Local $cI_Compname = @ComputerName, $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
    Local $colItems, $objWMIService, $objItem
    Dim $aUserInfo[1][14], $i = 1
   
    $objWMIService = ObjGet("winmgmts:\\" & $cI_Compname & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
   
    If IsObj($colItems) Then
        For $objItem In $colItems
            ReDim $aUserInfo[UBound($aUserInfo) + 1][14]
            $aUserInfo[$i][0]  = $objItem.Name
            $aUserInfo[$i][1]  = $objItem.Domain
            $aUserInfo[$i][2]  = $objItem.Status
            $aUserInfo[$i][3]  = $objItem.LocalAccount
            $aUserInfo[$i][4]  = $objItem.SID
            $aUserInfo[$i][5]  = $objItem.SIDType
            $aUserInfo[$i][6]  = $objItem.Description
            $aUserInfo[$i][7]  = $objItem.FullName
            $aUserInfo[$i][8]  = $objItem.Disabled
            $aUserInfo[$i][9]  = $objItem.Lockout
            $aUserInfo[$i][10] = $objItem.PasswordChangeable
            $aUserInfo[$i][11] = $objItem.PasswordExpires
            $aUserInfo[$i][12] = $objItem.PasswordRequired
            $aUserInfo[$i][13] = $objItem.AccountType
            $i += 1
        Next
        $aUserInfo[0][0] = UBound($aUserInfo) - 1
        If $aUserInfo[0][0] < 1 Then
            SetError(1, 1, 0)
        EndIf
    Else
        SetError(1, 2, 0)
    EndIf
EndFunc ;_ComputerGetUsers

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Or you could use my Active Directory UDF to check for existance of the user. For download please see my signature.

A very basic example (without error checking) would look like:

#include <ad.au3>
_AD_Open()
If _AD_ObjectExists(@Username) Then ...
_AD_Close()

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0