473,500 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Active directory search through vbnet

1 New Member
Hello, I am in the process of making a diagnostic program for our client machines and I am trying to get the container name as it contains the OU of the machine. I am able to do a search through vbnet but it only results in the computer name.
Dim ENTRY As System.DirectoryServices.DirectoryEntry = New
System.DirectoryServices.DirectoryEntry("LDAP://OU=Offices, DC=Test,DC=COM")

Dim MYSEARCHER As System.DirectoryServices.DirectorySearcher = New
System.DirectoryServices.DirectorySearcher(ENTRY)
MYSEARCHER.Filter = ("(&(objectclass=computer)(name=" + my.computer.name + ")) ")
Dim resEnt As System.DirectoryServices.SearchResult

For Each resEnt In MYSEARCHER.FindAll()

Try

Console.WriteLine(":Processing:" &
Mid(resEnt.GetDirectoryEntry().Name.ToString(), 4))

Catch ex As Exception

Console.WriteLine("Trying to Connect to: " &
resEnt.GetDirectoryEntry().Name.ToString() & vbCrLf & ex.Message.ToString())

End Try

Next
Mar 7 '17 #1
1 2991
Luk3r
300 Contributor
You need to tell your searcher to load AD properties. You can do so with this line, which will get all properties:
Expand|Select|Wrap|Line Numbers
  1. MYSEARCHER.PropertiesToLoad.Add("*")
After that, you can get a specific property by doing the following within your For loop, where "DistinguishedName" is the attribute you wish to get:
Expand|Select|Wrap|Line Numbers
  1. Dim DN As String = resent.Properties("DistinguishedName")(0)
Mar 7 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
734
by: Sara | last post by:
Dear Sir, I want to access to a special group in active directory but with this function I could just see that a special user is exist in active directory or not, I mean I want to see that a user...
3
3701
by: Ivan G. | last post by:
Hi. I'm trying to search active directory for users like this: DirectoryEntry entry = new DirectoryEntry(); //use default domain DirectorySearcher searcher = new DirectorySearcher(entry,...
2
9601
by: Netmonster | last post by:
Hello, I know how to search AD using the sAMAccountName if I know the exact name of the users NT login id, but, does any one know if you can search AD for sAMAccountName using wildcard chars? ...
0
1046
by: Glen Darling | last post by:
Morning everyone, I am looking for help with an active directory search I am trying to figure out. For a while now I have been banging my head against a wall trying to figure out how to...
0
1825
by: Kenneth Keeley | last post by:
Hi, I have been working on a Login page that uses ADSI to authenicate the users. I had this all working on my test system and on a second system connected to the live domain. Now it will only work...
0
1329
by: Matt | last post by:
Hi, I am looking for an Active Directory object selection for ASP.net 2. My ASP.net page has a text field to enter a user's or computer's LDAP path directly. And a "Find..." button that shall...
1
1985
by: ScriptNewbie | last post by:
Does anyone know if there is a way to search Active Directory with a username and return the computer name they are logged into?
3
5765
by: MuZZy | last post by:
Hi, I'm trying to find a way to call a standard ActiveDirectory search dialog from my C# app, so i can pick a domain or computer user an dreturn it to the app. It's a search like one showing...
2
1321
radcaesar
by: radcaesar | last post by:
Hi All, I had wrote a method to compare the users of AD and a oracle user table. Here using datarow, i search each users in AD. My code workin fine for first record, but it fails ffom...
1
941
by: Nandagopal | last post by:
The specified domain either does not exist or could not be contacted
0
7136
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,...
0
7182
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,...
1
6906
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...
0
7397
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...
0
5490
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,...
1
4923
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...
0
3110
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...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
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 ...

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.