共用方式為


Finding the Exchange Organization Name Using ADSI

Finding the Exchange Organization Name Using ADSI

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Visual Basic

' Finding the Exchange Organization Name Using ADSI
' Find the Exchange organization name by searching Active Directory.
' This can be run from any Windows 2000 or DSClient computer in the domain.
' This sample requires a reference to the following libraries:
' Active DS Type Library
' Microsoft ActiveX Data Objects 2.5 Library
     
Sub main()

Dim iAdRootDSE As ActiveDs.IADs
Dim Conn As New ADODB.Connection
Dim Com As New ADODB.Command
Dim Rs As ADODB.Recordset
Dim varConfigNC As Variant
Dim strQuery As String

' Get the configuration naming context.
Set iAdRootDSE = GetObject("LDAP://RootDSE")
varConfigNC = iAdRootDSE.Get("configurationNamingContext")

' Open the connection.
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"

' Build the query to find the organization.
strQuery = "<LDAP://" & varConfigNC & ">;(objectCategory=msExchOrganizationContainer);name,cn,distinguishedName;subtree"

Com.ActiveConnection = Conn
Com.CommandText = strQuery
Set Rs = Com.Execute

' Iterate through the results.
While Not Rs.EOF

' Output the name of the organization.
MsgBox "The organization name is: " & Rs.Fields("cn")
Rs.MoveNext
Wend

'Clean up.
Rs.Close
Conn.Close
Set Rs = Nothing
Set Com = Nothing
Set Conn = Nothing

End Sub

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.