Loading ...
Sorry, an error occurred while loading the content.
 

Re: [ADSI-DirSrv] Digest Number 435

Expand Messages
  • Graeme Dawkins
    Hi Have gone thru archives, Microsoft scripting guide and google and cannot find the answer to this ..... is it possible, via vb6, to search AD and find what
    Message 1 of 3 , Sep 1, 2004
      Hi

      Have gone thru archives, Microsoft scripting guide and google and cannot
      find the answer to this ..... is it possible, via vb6, to search AD and
      find what OU a given user is defined in ??

      Any help much appreciated
    • Brad Berson
      It looks to me like if you roughly follow the MS Scripting Guide s examples for querying for user attributes and ask for distinguishedName, you should be able
      Message 2 of 3 , Sep 1, 2004
        It looks to me like if you roughly follow the MS Scripting Guide's
        examples for querying for user attributes and ask for distinguishedName,
        you should be able to parse the answer for the OUs.


        -Rev. Brad


        -----Original Message-----
        From: Graeme Dawkins [mailto:graemeda@...]
        Sent: Wednesday, September 01, 2004 9:22 AM
        To: ADSIANDDirectoryServices@yahoogroups.com
        Subject: Re: [ADSI-DirSrv] Digest Number 435






        Hi

        Have gone thru archives, Microsoft scripting guide and google and cannot
        find the answer to this ..... is it possible, via vb6, to search AD and
        find what OU a given user is defined in ??

        Any help much appreciated






        Yahoo! Groups Links
      • Yantis, Richard
        Graeme- Here is some VB6 code we have been using. GETUSER finds the user (mobjUSR) and then calls GETUSERINFO to get the user properties, including the parent
        Message 3 of 3 , Sep 1, 2004
          Graeme-

          Here is some VB6 code we have been using. GETUSER finds the user (mobjUSR) and then calls GETUSERINFO to get the user properties, including the parent OU information.


          HTH,

          Richard
          ----------------------------------------
          Richard Yantis
          Technical Project Leader
          Administrative Systems
          Texas Christian University
          r.yantis@...


          =======================

          Public Sub GetUser(ByVal psUserName As String)
          Dim strADOQueryString As String ' ADO query string
          Dim objRS As ADODB.Recordset ' recordset object

          ClearErrorInfo
          ResetUserProperties
          On Error Resume Next

          mobjADOconn.Provider = "ADSDSOObject"
          mobjADOconn.Mode = adModeUnknown
          mobjADOconn.Open "ADs Provider"

          strADOQueryString = "<LDAP://" & mstrAdsRootPath & ">;(&(objectClass=user)(samAccountName=" + psUserName + "));cn,adspath;subtree"
          'strADOQueryString = "Select objectCategory,objectClass,sAMAccountName,Description,ADsPath,Name " & _
          ' "FROM '" & lstrADsPath & "' " '&

          Set objRS = mobjADOconn.Execute(strADOQueryString)
          If Err.Number <> 0 Then
          SetErrorInfo ("Execute: " & strADOQueryString)
          Exit Sub
          End If

          If Not objRS.EOF Then 'if not at EOF, then we found the user successfully!
          mstrUserAdsPath = objRS.Fields("adspath").value 'save the adspath
          Set mobjUSR = GetObject(mstrUserAdsPath) 'and use it to get the user oject
          Call GetUserInfo 'populate all of the users property variables
          Else
          mlngErrNumber = 901 'arbitrary error number
          mstrErrDescription = "User not found"
          mstrErrAction = "GetUser"
          End If

          'Clean up our objects
          objRS.Close
          Set objRS = Nothing
          Set mobjADOconn = Nothing

          End Sub

          -------------

          Private Sub GetUserInfo()
          Dim email As String
          Dim atLoc As Integer
          On Error Resume Next
          ClearErrorInfo
          mobjUSR.GetInfo

          mstrAccountName = mobjUSR.Get("samAccountName")
          mstrPrincipalName = mobjUSR.Get("UserPrincipalName")
          mstrLastName = mobjUSR.Get("sn")
          mstrFirstName = mobjUSR.Get("givenName")
          mstrDisplayName = mobjUSR.Get("displayname")
          mstrDepartment = mobjUSR.Get("Department")
          mstrDescription = mobjUSR.Get("Description")
          mstrTitle = mobjUSR.Get("Title")
          mstrScriptPath = mobjUSR.Get("Scriptpath")
          mbooAllowDialin = mobjUSR.Get("msNPAllowDialin")
          mstrEmplid = mobjUSR.Get("EmployeeID")
          mbooAccountDisabled = mobjUSR.AccountDisabled

          'mstrAccountExpires = mobjUSR.AccountExpirationDate 'this gives an error
          'mstrAccountExpires = mobjUSR.Get("AccountExpirationDate") 'this gives an error
          'mstrAccountExpires = mobjUSR.Get("AccountExpires") 'this gives an error
          'Sorry. I give up on getting the account expiration date. Hopefully this wont be a big issue.
          mstrAccountExpires = ""

          email = mobjUSR.Get("Mail")
          atLoc = InStr(1, email, "@") 'find @
          If atLoc > 1 Then 'found a @
          mstrEmailAddress = Mid(email, 1, atLoc - 1)
          mstrEmailDomain = Mid(email, atLoc + 1)
          End If

          Set mobjOU1 = GetObject(mobjUSR.Parent) 'jump up and get some parent container information
          mstrParentAdsPath = mobjOU1.ADsPath
          mstrParentClass = mobjOU1.Class
          mstrParentName = mobjOU1.Name
          mstrHomeOU = UCase(mstrParentName) 'the UCase is important due to IF statements later

          ==============================

          -----Original Message-----
          From: Graeme Dawkins [mailto:graemeda@...]
          Sent: Wednesday, September 01, 2004 8:22 AM
          To: ADSIANDDirectoryServices@yahoogroups.com
          Subject: Re: [ADSI-DirSrv] Digest Number 435






          Hi

          Have gone thru archives, Microsoft scripting guide and google and cannot
          find the answer to this ..... is it possible, via vb6, to search AD and
          find what OU a given user is defined in ??

          Any help much appreciated






          Yahoo! Groups Links
        Your message has been successfully submitted and would be delivered to recipients shortly.