| | |
try to access Active Directory in .NET -->system.runtime.interopservices.comexception
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2005
Posts: 1
Reputation:
Solved Threads: 0
try to access Active Directory in .NET -->system.runtime.interopservices.comexception
0
#1 Apr 4th, 2005
Hi everybody,
I've been searching for days to find a way to access Active directory database from my VB.NET appz and nothing made good results so far.. The Active directory DB is located onto a Win2k3 server but we have another on a NT4 server too.. Neither worked..
First, I was having a "Server not operational" error message, but fixed it in putting more parameters into the DirectoryEntry creation string. But now, I always get a "A referral was returned from the server(0x8007202B)" error message.. I tried to change as many things I could, but it still bugs me.. Any Idea?!??
Here's the source:
===================================================
Dim oRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & Me.mServer & ":389/DC=Dynanet,DC=com", "test", "test", AuthenticationTypes.Secure)
Dim oSearcher As DirectorySearcher = New DirectorySearcher(oRoot)
Dim oResult As SearchResult
Try
'it bugz at this line, right on the For declaration
For Each oResult In oSearcher.FindAll
If Not CStr(oResult.GetDirectoryEntry().Properties("cn").Value) = "" Then
Dim User As New LDAPUser(CStr(oResult.GetDirectoryEntry().Properties("uid").Value), _
CStr(oResult.GetDirectoryEntry().Properties("givenName").Value), _
CStr(oResult.GetDirectoryEntry().Properties("desc").Value), _
CStr(oResult.GetDirectoryEntry().Properties("email").Value), _
CStr(oResult.GetDirectoryEntry().Properties("phone").Value), _
CStr(oResult.GetDirectoryEntry().Properties("sms").Value))
Me.HashItems.Add(User.userId, User)
Me.LisItems.Add(User)
End If
Next oResult
Catch ex As Exception
MsgBox(ex.ToString)
Finally
oRoot = Nothing
oSearcher = Nothing
oResult = Nothing
End Try
==================================================
Thanks all!
I've been searching for days to find a way to access Active directory database from my VB.NET appz and nothing made good results so far.. The Active directory DB is located onto a Win2k3 server but we have another on a NT4 server too.. Neither worked..
First, I was having a "Server not operational" error message, but fixed it in putting more parameters into the DirectoryEntry creation string. But now, I always get a "A referral was returned from the server(0x8007202B)" error message.. I tried to change as many things I could, but it still bugs me.. Any Idea?!??Here's the source:
===================================================
Dim oRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & Me.mServer & ":389/DC=Dynanet,DC=com", "test", "test", AuthenticationTypes.Secure)
Dim oSearcher As DirectorySearcher = New DirectorySearcher(oRoot)
Dim oResult As SearchResult
Try
'it bugz at this line, right on the For declaration
For Each oResult In oSearcher.FindAll
If Not CStr(oResult.GetDirectoryEntry().Properties("cn").Value) = "" Then
Dim User As New LDAPUser(CStr(oResult.GetDirectoryEntry().Properties("uid").Value), _
CStr(oResult.GetDirectoryEntry().Properties("givenName").Value), _
CStr(oResult.GetDirectoryEntry().Properties("desc").Value), _
CStr(oResult.GetDirectoryEntry().Properties("email").Value), _
CStr(oResult.GetDirectoryEntry().Properties("phone").Value), _
CStr(oResult.GetDirectoryEntry().Properties("sms").Value))
Me.HashItems.Add(User.userId, User)
Me.LisItems.Add(User)
End If
Next oResult
Catch ex As Exception
MsgBox(ex.ToString)
Finally
oRoot = Nothing
oSearcher = Nothing
oResult = Nothing
End Try
==================================================
Thanks all!
Re: try to access Active Directory in .NET -->system.runtime.interopservices.comexception
0
#2 Apr 8th, 2005
I've found that the easiest way to query the AD Directory is by using the Active Directory Provider for ADO. Here's the code for a console app that will give you the distinguished names for all the computers in the built-in Computers container. Just give the app your FQDN and it should give you results. Also keep in mind that I did not include ANY error checking or handling in this.
Hope it helps!
Andy
Imports ADODB
Imports System
Module ListADComputers
Sub Main()
' define local variables
Dim oConn As New ADODB.Connection
Dim oRS As New ADODB.Recordset
Dim oComm As New ADODB.Command
Dim strComputerName As String
Dim strDomainName As String
' get console parameters
System.Console.WriteLine("What is the name of the AD Domain you wish to query?")
strDomainName = System.Console.ReadLine()
' set connection properties
With oConn
.Provider = "ADsDSOObject"
.Open("Active Directory Provider")
End With
' set command properties
With oComm
.ActiveConnection = oConn
.CommandText = "<LDAP://CN=Computers,DC=" & Left(strDomainName, Len(strDomainName) - 4) & ",DC=" & _
Right(strDomainName, 3) & ">;(objectClass=computer);distinguishedName"
End With
' open recordset
oRS = oComm.Execute
If Not oRS.EOF Then
oRS.MoveFirst()
Do Until oRS.EOF
System.Console.WriteLine(oRS.Fields("distinguishedName").Value)
oRS.MoveNext()
Loop
End If
' clean up objects
oRS.Close()
oConn.Close()
oRS = Nothing
oComm = Nothing
oConn = Nothing
End Sub
End Module
Hope it helps!
Andy
Imports ADODB
Imports System
Module ListADComputers
Sub Main()
' define local variables
Dim oConn As New ADODB.Connection
Dim oRS As New ADODB.Recordset
Dim oComm As New ADODB.Command
Dim strComputerName As String
Dim strDomainName As String
' get console parameters
System.Console.WriteLine("What is the name of the AD Domain you wish to query?")
strDomainName = System.Console.ReadLine()
' set connection properties
With oConn
.Provider = "ADsDSOObject"
.Open("Active Directory Provider")
End With
' set command properties
With oComm
.ActiveConnection = oConn
.CommandText = "<LDAP://CN=Computers,DC=" & Left(strDomainName, Len(strDomainName) - 4) & ",DC=" & _
Right(strDomainName, 3) & ">;(objectClass=computer);distinguishedName"
End With
' open recordset
oRS = oComm.Execute
If Not oRS.EOF Then
oRS.MoveFirst()
Do Until oRS.EOF
System.Console.WriteLine(oRS.Fields("distinguishedName").Value)
oRS.MoveNext()
Loop
End If
' clean up objects
oRS.Close()
oConn.Close()
oRS = Nothing
oComm = Nothing
oConn = Nothing
End Sub
End Module
![]() |
Similar Threads
- COMException error, class not registered (VB.NET)
- use excel in vb.net 2003 (VB.NET)
- Problem with Crystal Report in ASP.NET (ASP.NET)
- Unable to create an excel file in VB.net (VB.NET)
- Email Sending Problem in ASP.NET (ASP.NET)
- Sonalika (VB.NET)
- move previouse record in VB.net (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Microsoft Visual Basic book and a short intro.
- Next Thread: code for selectedIndexChanged event
| Thread Tools | Search this Thread |
.net .net2008 2008 access account add advanced application array basic beginner browser button buttons click code combo cpu cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic employees excel exists fade filter forms generatetags html images input intel internet listview mobile module monitor mysql net number objects open panel pdf picturebox picturebox2 port position print printing printpreview problem regex reuse right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver storedprocedure survey temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet vista visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





