VB .Net with ADSI problem

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
I am developing on a Windows XP desktop connected to our domain. The domain
controller is a Windows 2003 server machine
 
I got it, you shouldn't use old VB-GetObject function, use
System.DirectoryServices
 
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,
 
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)
 
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
 
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)
 
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
 
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
 
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
 
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
 
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...
 
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...
 
Back
Top