VB .Net with ADSI problem

G

Guest

I am trying to develop an app using ADSI. I have the following code:

Dim ADSUser As IADsUser

ADSUser = GetObject("LDAP://CN=jonsmith,CN=users,DC=domain,DC=com")

MessageBox.Show(ADSUser.EmailAddress)

When i try and run the program, i get the following error:

Cannot create ActiveX component

Any ideas what is causing this?
 
G

Guest

I am developing on a Windows XP desktop connected to our domain. The domain
controller is a Windows 2003 server machine
 
A

Alexey Smirnov

I got it, you shouldn't use old VB-GetObject function, use
System.DirectoryServices
 
A

Alexey Smirnov

an example

Imports System.DirectoryServices

.....
Dim myDirectoryEntry As DirectoryEntry
myDirectoryEntry = New
DirectoryEntry("LDAP://CN=jonsmith,CN=users,DC=domain,DC=com")

Dim ADSUser As ActiveDs.IADsUser
ADSUser = myDirectoryEntry.NativeObject()

Regards,
 
G

Guest

Thanks for that, i have made a little more progress now, but it is still not
working. I am getting "No such object on the server", but i know the object
exists as it is my user!!!!

The code is:

Dim myDirectoryEntry As DirectoryEntry
myDirectoryEntry = New DirectoryEntry("LDAP://CN=""Jonathan
Smith"",CN=""Edmundson Users"",DC=SERVICECENTRE,DC=local")

Dim ADSUser As ActiveDs.IADsUser
ADSUser = myDirectoryEntry.NativeObject()


MessageBox.Show(ADSUser.EmailAddress)
 
A

Alexey Smirnov

sorry, I think I told you more code than you needed

Dim myDirectoryEntry As DirectoryEntry
myDirectoryEntry = New DirectoryEntry("LDAP://...")
Console.WriteLine("EmailAddress: " &
myDirectoryEntry.Properties("mail").Value)

This code is working for me.

Please check
 
G

Guest

Sorry to be a pain, and i really appreciate your help. But, i am now getting
the message "a referral was returned from the server". The code is:

Dim myDirectoryEntry As DirectoryEntry
myDirectoryEntry = New DirectoryEntry("LDAP://CN=Jonathan
Smith,DC=sc-file,DC=servicecentre")
Console.WriteLine("EmailAddress: " &
myDirectoryEntry.Properties("mail").Value)
 
A

Alexey Smirnov

Where do you use it, is it Windows app, or ASP.NET?
I tested it in WinForms application and my account has permissions to
request AD.

On which line you get that error?

BR,
Alexey
 
G

Guest

The error is occurring on this line:
Console.Write("EmailAddress: " & myDirectoryEntry.Properties("mail").Value)

i have tried running the code as an administrative user, but get the same
result
 
A

Alexey Smirnov

well, then try to enumerate all properties at your entry

add this code
Dim p As String

Dim v As Object

For Each p In myDirectoryEntry.Properties.PropertyNames

For Each v In myDirectoryEntry.Properties(p)

Console.WriteLine(p & "=" & v.ToString)

Next v

Next p

instead the Console.Write("EmailAddress: " &
myDirectoryEntry.Properties("mail").Value)

You should get a list of properties/values in the Console Window
 
G

Guest

Yeah, that seems to have worked. I reckon the problem is my LDAP query is
wrong. I will spend some time sorting the query syntax now.

Thanks for all your help
 
G

Guest

THanks for that. What i am trying to achieve is to create a Windows
"dashboard" that will give me key data about my Exchange server.

Is this achievable by doing LDAP queries on my mail server?

I want to know things like "who is the domain mail server", what version of
exchange is it running, database path etc...
 
A

Alexey Smirnov

yes, if you have permissions to do that


Jonathan Smith said:
THanks for that. What i am trying to achieve is to create a Windows
"dashboard" that will give me key data about my Exchange server.

Is this achievable by doing LDAP queries on my mail server?

I want to know things like "who is the domain mail server", what version
of
exchange is it running, database path etc...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top