473,832 Members | 2,187 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 1526
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
3142
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
5975
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
2863
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
994
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
3077
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
6240
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
16338
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
10781
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10499
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
10541
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
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
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...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4421
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
3972
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.