473,803 Members | 3,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DirectoryServic e Query... Help

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(ByV al inSAM As String, ByVal inType As String)
As String
Try

Dim sPath As String = "LDAP://netdomain.domai n.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 DirectorySearch er(myDirectory)
Dim mySearchResultC oll As SearchResultCol lection
Dim mySearchResult As SearchResult
Dim myResultPropCol l As ResultPropertyC ollection
Dim myResultPropVal ueColl As ResultPropertyV alueCollection
'Build LDAP query
mySearcher.Filt er = ("(&(objectClas s=user)(samacco untname=" &
SamAccount & "))")
mySearchResultC oll = mySearcher.Find All()

</code>
Nov 19 '05 #1
5 1520
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_hotm ail.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(ByV al inSAM As String, ByVal inType As String)
As String
Try

Dim sPath As String = "LDAP://netdomain.domai n.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 DirectorySearch er(myDirectory)
Dim mySearchResultC oll As SearchResultCol lection
Dim mySearchResult As SearchResult
Dim myResultPropCol l As ResultPropertyC ollection
Dim myResultPropVal ueColl As ResultPropertyV alueCollection
'Build LDAP query
mySearcher.Filt er = ("(&(objectClas s=user)(samacco untname=" &
SamAccount & "))")
mySearchResultC oll = mySearcher.Find All()

</code>


Nov 19 '05 #2
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 mySearchResultC oll In mySearcher.Find All()

and if so where???

I really appritiate the advice!
Thanks
<code>

Public Function GetUserInfo(ByV al inType As String) As String
Try

Dim sPath As String = "LDAP://netdomain.domai n.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 DirectorySearch er(myDirectory)
Dim mySearchResultC oll As SearchResultCol lection
Dim mySearchResult As SearchResult
Dim myResultPropCol l As ResultPropertyC ollection
Dim myResultPropVal ueColl As ResultPropertyV alueCollection
'Build LDAP query
mySearcher.Filt er = ("(&(objectClas s=user))")
mySearchResultC oll = mySearcher.Find All()
'I expect only one user from search result
Select Case mySearchResultC oll.Count
Case 0
Return "Null"
Exit Function

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

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

'displayname, mail
'Retrieve from the properties collection the display name and
email of the user
myResultPropVal ueColl = myResultPropCol l.Item(inType)
Return CStr(myResultPr opValueColl.Ite m(0))

Catch ex As System.Exceptio n

'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_hotm ail.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(ByV al inSAM As String, ByVal inType As String)
As String
Try

Dim sPath As String = "LDAP://netdomain.domai n.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 DirectorySearch er(myDirectory)
Dim mySearchResultC oll As SearchResultCol lection
Dim mySearchResult As SearchResult
Dim myResultPropCol l As ResultPropertyC ollection
Dim myResultPropVal ueColl As ResultPropertyV alueCollection
'Build LDAP query
mySearcher.Filt er = ("(&(objectClas s=user)(samacco untname=" &
SamAccount & "))")
mySearchResultC oll = mySearcher.Find All()

</code>


Nov 19 '05 #3
Hi Tim:

Yes, you want to loop through mySearchResultC oll 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_hotm ail.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 mySearchResultC oll In mySearcher.Find All()

and if so where???

I really appritiate the advice!
Thanks
<code>

Public Function GetUserInfo(ByV al inType As String) As String
Try

Dim sPath As String = "LDAP://netdomain.domai n.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 DirectorySearch er(myDirectory)
Dim mySearchResultC oll As SearchResultCol lection
Dim mySearchResult As SearchResult
Dim myResultPropCol l As ResultPropertyC ollection
Dim myResultPropVal ueColl As ResultPropertyV alueCollection
'Build LDAP query
mySearcher.Filt er = ("(&(objectClas s=user))")
mySearchResultC oll = mySearcher.Find All()
'I expect only one user from search result
Select Case mySearchResultC oll.Count
Case 0
Return "Null"
Exit Function

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

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

'displayname, mail
'Retrieve from the properties collection the display name and
email of the user
myResultPropVal ueColl = myResultPropCol l.Item(inType)
Return CStr(myResultPr opValueColl.Ite m(0))

Catch ex As System.Exceptio n

'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_hotm ail.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(ByV al inSAM As String, ByVal inType As String)
>As String
> Try
>
> Dim sPath As String = "LDAP://netdomain.domai n.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 DirectorySearch er(myDirectory)
> Dim mySearchResultC oll As SearchResultCol lection
> Dim mySearchResult As SearchResult
> Dim myResultPropCol l As ResultPropertyC ollection
> Dim myResultPropVal ueColl As ResultPropertyV alueCollection
> 'Build LDAP query
> mySearcher.Filt er = ("(&(objectClas s=user)(samacco untname=" &
>SamAccount & "))")
> mySearchResultC oll = mySearcher.Find All()
>
></code>



Nov 19 '05 #4
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 mySearchResultC oll 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_hotm ail.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 mySearchResultC oll In mySearcher.Find All()

and if so where???

I really appritiate the advice!
Thanks
<code>

Public Function GetUserInfo(ByV al inType As String) As String
Try

Dim sPath As String = "LDAP://netdomain.domai n.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 DirectorySearch er(myDirectory)
Dim mySearchResultC oll As SearchResultCol lection
Dim mySearchResult As SearchResult
Dim myResultPropCol l As ResultPropertyC ollection
Dim myResultPropVal ueColl As ResultPropertyV alueCollection
'Build LDAP query
mySearcher.Filt er = ("(&(objectClas s=user))")
mySearchResultC oll = mySearcher.Find All()
'I expect only one user from search result
Select Case mySearchResultC oll.Count
Case 0
Return "Null"
Exit Function

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

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

'displayname, mail
'Retrieve from the properties collection the display name and
email of the user
myResultPropVal ueColl = myResultPropCol l.Item(inType)
Return CStr(myResultPr opValueColl.Ite m(0))

Catch ex As System.Exceptio n

'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_hotm ail.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(ByV al inSAM As String, ByVal inType As String)
>As String
> Try
>
> Dim sPath As String = "LDAP://netdomain.domai n.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 DirectorySearch er(myDirectory)
> Dim mySearchResultC oll As SearchResultCol lection
> Dim mySearchResult As SearchResult
> Dim myResultPropCol l As ResultPropertyC ollection
> Dim myResultPropVal ueColl As ResultPropertyV alueCollection
> 'Build LDAP query
> mySearcher.Filt er = ("(&(objectClas s=user)(samacco untname=" &
>SamAccount & "))")
> mySearchResultC oll = mySearcher.Find All()
>
></code>


Nov 19 '05 #5
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_hotm ail.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...


Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3140
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use SUBSTRING(ProductName, 1, CHARINDEX('(', ProductName)-2). I can get this result, but I had to use several views (totally inefficient). I think this can be done in one efficient/fast query, but I can't think of one. In the case that one query is not...
7
5972
by: Simon Bailey | last post by:
How do you created a query in VB? I have a button on a form that signifies a certain computer in a computer suite. On clicking on this button i would like to create a query searching for all details invovling that computer, for the user to then view. Any ideas on some code? Many thanks for any help.
4
2862
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table query. I'm having trouble doing it. Help! Here is my code so far: Sub OldRegionQuery()
0
993
by: Justin Rich | last post by:
I would like to find a way to use the data grid to hook in to the AD. Was looking at the choices for data sources and i didnt see a way to do it, but figured i would ask to see if i missed something using C#, connecting to the AD with System.Directoryservice and would like to use a data grid to show and manipulate this data. Any idea how this can be done? Thank
0
929
by: Tim::.. | last post by:
Can someone please help! I am trying to use DirectoryServices with a datagrid to show the different users in our AD and then have a button that will show the details of the selected user and give the ability to edit the users details! I'm having a problem getting the users details to show up when you click a button in the datagrid and would really appritiate help solving this... The following article gives some guidance but it is in...
0
999
by: Tim::.. | last post by:
Question 1... Hi can someone please tell me why I can't put the following LDAP string into my web.config fill as an <appSetting> <appSettings> <add key="strLDAP" value="'LDAP://doamin.domain.com', 'Administrator', 'Password'" /> </appSettings>
36
3074
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I have set up a Query to show only records that meet a certain criteria...therefore excluding all of the records that do not meet this criteria (just for the record the criteria is any record within my database that falls within two months of its "Due...
10
6238
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this cross-tab query I am using a simple query with no grouping where I am filtering some data out in the criteria line. I have been out of access for a couple years but I remember in the past I had a solution for this but I can't remember. Any help...
11
16335
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction. We have been using oracle client 10.1.0.2 with it's odbc for a while without problem. The problem arose when we decided to reconnect all the tables and save password. Some query became suddenly very slow. Then I've discovered that the tables...
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.