DirectoryService Query... Help

Discussion in 'ASP .Net' started by =?Utf-8?B?VGltOjouLg==?=, Mar 29, 2005.

  1. Hi can someone please tell me how I change this directory service query so
    that it searches through each record in the active directory and returns all
    the accounts!

    At the moment I can only get the query to return one account at a time!

    I presume I have to create some kind of loop on the following so I return
    all the users SAM info????

    Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))

    I would be really grateful for any help!

    Thanks


    <code>

    Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As String)
    As String
    Try

    Dim sPath As String = "LDAP://netdomain.domain.com"
    Dim SamAccount As String = Right(inSAM, Len(inSAM) -
    InStr(inSAM, "\"))
    'pass the user account and password for your Admin Account.
    Dim myDirectory As New DirectoryEntry(sPath, "administrator",
    "password")
    Dim mySearcher As New DirectorySearcher(myDirectory)
    Dim mySearchResultColl As SearchResultCollection
    Dim mySearchResult As SearchResult
    Dim myResultPropColl As ResultPropertyCollection
    Dim myResultPropValueColl As ResultPropertyValueCollection
    'Build LDAP query
    mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" &
    SamAccount & "))")
    mySearchResultColl = mySearcher.FindAll()

    </code>
     
    =?Utf-8?B?VGltOjouLg==?=, Mar 29, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?VGltOjouLg==?=

    Scott Allen Guest

    Hi Tim:

    The filter seems to be looking for a specific user account by
    including samAccountName. Have you tried removing it from the filter?

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Mon, 28 Mar 2005 23:59:03 -0800, "Tim::.." <myatix_at_hotmail.com>
    wrote:

    >Hi can someone please tell me how I change this directory service query so
    >that it searches through each record in the active directory and returns all
    >the accounts!
    >
    >At the moment I can only get the query to return one account at a time!
    >
    >I presume I have to create some kind of loop on the following so I return
    >all the users SAM info????
    >
    > Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))
    >
    >I would be really grateful for any help!
    >
    >Thanks
    >
    >
    ><code>
    >
    >Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As String)
    >As String
    > Try
    >
    > Dim sPath As String = "LDAP://netdomain.domain.com"
    > Dim SamAccount As String = Right(inSAM, Len(inSAM) -
    >InStr(inSAM, "\"))
    > 'pass the user account and password for your Admin Account.
    > Dim myDirectory As New DirectoryEntry(sPath, "administrator",
    >"password")
    > Dim mySearcher As New DirectorySearcher(myDirectory)
    > Dim mySearchResultColl As SearchResultCollection
    > Dim mySearchResult As SearchResult
    > Dim myResultPropColl As ResultPropertyCollection
    > Dim myResultPropValueColl As ResultPropertyValueCollection
    > 'Build LDAP query
    > mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" &
    >SamAccount & "))")
    > mySearchResultColl = mySearcher.FindAll()
    >
    ></code>
     
    Scott Allen, Mar 29, 2005
    #2
    1. Advertising

  3. Hi Scott,

    Thanks for the advice! The trouble is that it returns the same user
    information again and again! Do I have to put a

    For Each mySearchResultColl In mySearcher.FindAll()

    and if so where???

    I really appritiate the advice!
    Thanks


    <code>

    Public Function GetUserInfo(ByVal inType As String) As String
    Try

    Dim sPath As String = "LDAP://netdomain.domain.com"
    'Dim SamAccount As String = Right(inSAM, Len(inSAM) -
    InStr(inSAM, "\"))
    'pass the user account and password for your Admin Account.
    Dim myDirectory As New DirectoryEntry(sPath, "administrator",
    "password")
    Dim mySearcher As New DirectorySearcher(myDirectory)
    Dim mySearchResultColl As SearchResultCollection
    Dim mySearchResult As SearchResult
    Dim myResultPropColl As ResultPropertyCollection
    Dim myResultPropValueColl As ResultPropertyValueCollection
    'Build LDAP query
    mySearcher.Filter = ("(&(objectClass=user))")
    mySearchResultColl = mySearcher.FindAll()
    'I expect only one user from search result
    Select Case mySearchResultColl.Count
    Case 0
    Return "Null"
    Exit Function

    End Select
    'Get the search result from the collection
    mySearchResult = mySearchResultColl.Item(0)

    'Get the Properites, they contain the usefull info
    myResultPropColl = mySearchResult.Properties

    'displayname, mail
    'Retrieve from the properties collection the display name and
    email of the user
    myResultPropValueColl = myResultPropColl.Item(inType)
    Return CStr(myResultPropValueColl.Item(0))

    Catch ex As System.Exception

    'do some error return here.
    End Try
    End Function

    "Scott Allen" wrote:

    > Hi Tim:
    >
    > The filter seems to be looking for a specific user account by
    > including samAccountName. Have you tried removing it from the filter?
    >
    > --
    > Scott
    > http://www.OdeToCode.com/blogs/scott/
    >
    > On Mon, 28 Mar 2005 23:59:03 -0800, "Tim::.." <myatix_at_hotmail.com>
    > wrote:
    >
    > >Hi can someone please tell me how I change this directory service query so
    > >that it searches through each record in the active directory and returns all
    > >the accounts!
    > >
    > >At the moment I can only get the query to return one account at a time!
    > >
    > >I presume I have to create some kind of loop on the following so I return
    > >all the users SAM info????
    > >
    > > Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))
    > >
    > >I would be really grateful for any help!
    > >
    > >Thanks
    > >
    > >
    > ><code>
    > >
    > >Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As String)
    > >As String
    > > Try
    > >
    > > Dim sPath As String = "LDAP://netdomain.domain.com"
    > > Dim SamAccount As String = Right(inSAM, Len(inSAM) -
    > >InStr(inSAM, "\"))
    > > 'pass the user account and password for your Admin Account.
    > > Dim myDirectory As New DirectoryEntry(sPath, "administrator",
    > >"password")
    > > Dim mySearcher As New DirectorySearcher(myDirectory)
    > > Dim mySearchResultColl As SearchResultCollection
    > > Dim mySearchResult As SearchResult
    > > Dim myResultPropColl As ResultPropertyCollection
    > > Dim myResultPropValueColl As ResultPropertyValueCollection
    > > 'Build LDAP query
    > > mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" &
    > >SamAccount & "))")
    > > mySearchResultColl = mySearcher.FindAll()
    > >
    > ></code>

    >
    >
     
    =?Utf-8?B?VGltOjouLg==?=, Mar 29, 2005
    #3
  4. =?Utf-8?B?VGltOjouLg==?=

    Scott Allen Guest

    Hi Tim:

    Yes, you want to loop through mySearchResultColl with For Each or
    other looping logic. Currently the code only appears to be looking at
    Item(0) - the first object in the collection.

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Tue, 29 Mar 2005 07:11:02 -0800, "Tim::.." <myatix_at_hotmail.com>
    wrote:

    >Hi Scott,
    >
    >Thanks for the advice! The trouble is that it returns the same user
    >information again and again! Do I have to put a
    >
    > For Each mySearchResultColl In mySearcher.FindAll()
    >
    >and if so where???
    >
    >I really appritiate the advice!
    >Thanks
    >
    >
    ><code>
    >
    > Public Function GetUserInfo(ByVal inType As String) As String
    > Try
    >
    > Dim sPath As String = "LDAP://netdomain.domain.com"
    > 'Dim SamAccount As String = Right(inSAM, Len(inSAM) -
    >InStr(inSAM, "\"))
    > 'pass the user account and password for your Admin Account.
    > Dim myDirectory As New DirectoryEntry(sPath, "administrator",
    >"password")
    > Dim mySearcher As New DirectorySearcher(myDirectory)
    > Dim mySearchResultColl As SearchResultCollection
    > Dim mySearchResult As SearchResult
    > Dim myResultPropColl As ResultPropertyCollection
    > Dim myResultPropValueColl As ResultPropertyValueCollection
    > 'Build LDAP query
    > mySearcher.Filter = ("(&(objectClass=user))")
    > mySearchResultColl = mySearcher.FindAll()
    > 'I expect only one user from search result
    > Select Case mySearchResultColl.Count
    > Case 0
    > Return "Null"
    > Exit Function
    >
    > End Select
    > 'Get the search result from the collection
    > mySearchResult = mySearchResultColl.Item(0)
    >
    > 'Get the Properites, they contain the usefull info
    > myResultPropColl = mySearchResult.Properties
    >
    > 'displayname, mail
    > 'Retrieve from the properties collection the display name and
    >email of the user
    > myResultPropValueColl = myResultPropColl.Item(inType)
    > Return CStr(myResultPropValueColl.Item(0))
    >
    > Catch ex As System.Exception
    >
    > 'do some error return here.
    > End Try
    > End Function
    >
    >"Scott Allen" wrote:
    >
    >> Hi Tim:
    >>
    >> The filter seems to be looking for a specific user account by
    >> including samAccountName. Have you tried removing it from the filter?
    >>
    >> --
    >> Scott
    >> http://www.OdeToCode.com/blogs/scott/
    >>
    >> On Mon, 28 Mar 2005 23:59:03 -0800, "Tim::.." <myatix_at_hotmail.com>
    >> wrote:
    >>
    >> >Hi can someone please tell me how I change this directory service query so
    >> >that it searches through each record in the active directory and returns all
    >> >the accounts!
    >> >
    >> >At the moment I can only get the query to return one account at a time!
    >> >
    >> >I presume I have to create some kind of loop on the following so I return
    >> >all the users SAM info????
    >> >
    >> > Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))
    >> >
    >> >I would be really grateful for any help!
    >> >
    >> >Thanks
    >> >
    >> >
    >> ><code>
    >> >
    >> >Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As String)
    >> >As String
    >> > Try
    >> >
    >> > Dim sPath As String = "LDAP://netdomain.domain.com"
    >> > Dim SamAccount As String = Right(inSAM, Len(inSAM) -
    >> >InStr(inSAM, "\"))
    >> > 'pass the user account and password for your Admin Account.
    >> > Dim myDirectory As New DirectoryEntry(sPath, "administrator",
    >> >"password")
    >> > Dim mySearcher As New DirectorySearcher(myDirectory)
    >> > Dim mySearchResultColl As SearchResultCollection
    >> > Dim mySearchResult As SearchResult
    >> > Dim myResultPropColl As ResultPropertyCollection
    >> > Dim myResultPropValueColl As ResultPropertyValueCollection
    >> > 'Build LDAP query
    >> > mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" &
    >> >SamAccount & "))")
    >> > mySearchResultColl = mySearcher.FindAll()
    >> >
    >> ></code>

    >>
    >>
     
    Scott Allen, Mar 29, 2005
    #4
  5. Thanks for the HELP!

    I don't suppose you know any really good resources for directory services
    and ADSI??? I'm trying to create a web app that allows one of our users to
    update certain aspects of the AD!

    Also want to create a contacts app that pulls details from the AD!

    Thanks AGAIN...


    "Scott Allen" wrote:

    > Hi Tim:
    >
    > Yes, you want to loop through mySearchResultColl with For Each or
    > other looping logic. Currently the code only appears to be looking at
    > Item(0) - the first object in the collection.
    >
    > --
    > Scott
    > http://www.OdeToCode.com/blogs/scott/
    >
    > On Tue, 29 Mar 2005 07:11:02 -0800, "Tim::.." <myatix_at_hotmail.com>
    > wrote:
    >
    > >Hi Scott,
    > >
    > >Thanks for the advice! The trouble is that it returns the same user
    > >information again and again! Do I have to put a
    > >
    > > For Each mySearchResultColl In mySearcher.FindAll()
    > >
    > >and if so where???
    > >
    > >I really appritiate the advice!
    > >Thanks
    > >
    > >
    > ><code>
    > >
    > > Public Function GetUserInfo(ByVal inType As String) As String
    > > Try
    > >
    > > Dim sPath As String = "LDAP://netdomain.domain.com"
    > > 'Dim SamAccount As String = Right(inSAM, Len(inSAM) -
    > >InStr(inSAM, "\"))
    > > 'pass the user account and password for your Admin Account.
    > > Dim myDirectory As New DirectoryEntry(sPath, "administrator",
    > >"password")
    > > Dim mySearcher As New DirectorySearcher(myDirectory)
    > > Dim mySearchResultColl As SearchResultCollection
    > > Dim mySearchResult As SearchResult
    > > Dim myResultPropColl As ResultPropertyCollection
    > > Dim myResultPropValueColl As ResultPropertyValueCollection
    > > 'Build LDAP query
    > > mySearcher.Filter = ("(&(objectClass=user))")
    > > mySearchResultColl = mySearcher.FindAll()
    > > 'I expect only one user from search result
    > > Select Case mySearchResultColl.Count
    > > Case 0
    > > Return "Null"
    > > Exit Function
    > >
    > > End Select
    > > 'Get the search result from the collection
    > > mySearchResult = mySearchResultColl.Item(0)
    > >
    > > 'Get the Properites, they contain the usefull info
    > > myResultPropColl = mySearchResult.Properties
    > >
    > > 'displayname, mail
    > > 'Retrieve from the properties collection the display name and
    > >email of the user
    > > myResultPropValueColl = myResultPropColl.Item(inType)
    > > Return CStr(myResultPropValueColl.Item(0))
    > >
    > > Catch ex As System.Exception
    > >
    > > 'do some error return here.
    > > End Try
    > > End Function
    > >
    > >"Scott Allen" wrote:
    > >
    > >> Hi Tim:
    > >>
    > >> The filter seems to be looking for a specific user account by
    > >> including samAccountName. Have you tried removing it from the filter?
    > >>
    > >> --
    > >> Scott
    > >> http://www.OdeToCode.com/blogs/scott/
    > >>
    > >> On Mon, 28 Mar 2005 23:59:03 -0800, "Tim::.." <myatix_at_hotmail.com>
    > >> wrote:
    > >>
    > >> >Hi can someone please tell me how I change this directory service query so
    > >> >that it searches through each record in the active directory and returns all
    > >> >the accounts!
    > >> >
    > >> >At the moment I can only get the query to return one account at a time!
    > >> >
    > >> >I presume I have to create some kind of loop on the following so I return
    > >> >all the users SAM info????
    > >> >
    > >> > Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))
    > >> >
    > >> >I would be really grateful for any help!
    > >> >
    > >> >Thanks
    > >> >
    > >> >
    > >> ><code>
    > >> >
    > >> >Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As String)
    > >> >As String
    > >> > Try
    > >> >
    > >> > Dim sPath As String = "LDAP://netdomain.domain.com"
    > >> > Dim SamAccount As String = Right(inSAM, Len(inSAM) -
    > >> >InStr(inSAM, "\"))
    > >> > 'pass the user account and password for your Admin Account.
    > >> > Dim myDirectory As New DirectoryEntry(sPath, "administrator",
    > >> >"password")
    > >> > Dim mySearcher As New DirectorySearcher(myDirectory)
    > >> > Dim mySearchResultColl As SearchResultCollection
    > >> > Dim mySearchResult As SearchResult
    > >> > Dim myResultPropColl As ResultPropertyCollection
    > >> > Dim myResultPropValueColl As ResultPropertyValueCollection
    > >> > 'Build LDAP query
    > >> > mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" &
    > >> >SamAccount & "))")
    > >> > mySearchResultColl = mySearcher.FindAll()
    > >> >
    > >> ></code>
    > >>
    > >>

    >
    >
     
    =?Utf-8?B?VGltOjouLg==?=, Mar 29, 2005
    #5
  6. =?Utf-8?B?VGltOjouLg==?=

    Scott Allen Guest

    15seconds.com used to have a lot of good ADSI info, but it doesn't
    look like they have updated the site in quite some time. It is one of
    those sticky tar pit like areas that people try to avoid,
    unfortunately for you :)

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Tue, 29 Mar 2005 07:43:03 -0800, "Tim::.." <myatix_at_hotmail.com>
    wrote:

    >Thanks for the HELP!
    >
    >I don't suppose you know any really good resources for directory services
    >and ADSI??? I'm trying to create a web app that allows one of our users to
    >update certain aspects of the AD!
    >
    >Also want to create a contacts app that pulls details from the AD!
    >
    >Thanks AGAIN...
    >
    >
     
    Scott Allen, Mar 29, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    DirectoryService Problem...

    =?Utf-8?B?VGltOjouLg==?=, Feb 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,971
    =?Utf-8?B?VGltOjouLg==?=
    Feb 8, 2005
  2. =?Utf-8?B?VGltOjouLg==?=

    VB DirectoryService Guru... HELP???

    =?Utf-8?B?VGltOjouLg==?=, Feb 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    350
    =?Utf-8?B?VGltOjouLg==?=
    Feb 9, 2005
  3. =?Utf-8?B?VGltOjouLg==?=

    HELP... LDAP/ DirectoryService Guru

    =?Utf-8?B?VGltOjouLg==?=, Feb 18, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    315
    =?Utf-8?B?VGltOjouLg==?=
    Feb 18, 2005
  4. =?Utf-8?B?VGltOjouLg==?=

    ADSI... DirectoryService... DataGrid

    =?Utf-8?B?VGltOjouLg==?=, Mar 31, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    361
    Patrick Olurotimi Ige
    Mar 31, 2005
  5. Buster Baxter
    Replies:
    0
    Views:
    627
    Buster Baxter
    Aug 31, 2006
Loading...

Share This Page