Getting the Entry ID of a Virtual Server Using Its Name
Getting the Entry ID of a Virtual Server Using Its Name
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.
The following example returns the entry ID for the specified virtual server.
Visual Basic
'////////////////////////////////////////////////////////////////////// ' Function: getEntryIDfromName() ' Purpose: Gets the entry ID for the virtual server from the name passed in. ' ' Input: szDomainName: Domain of the Exchange organization ' szOrganizationName: Name of Exchange Organization ' szAdministrativeGroupName: Name of Administrative Group ' szServerName: Name of server to use ' szVirtualServerName: Name of the virtual server whose ID we want ' szUserName: Admin Username ' szUserPwd: Admin pwd ' szDirectoryServer: Name of the Directory Server ' ' Output: getEntryIDfromName: Contains Error code (if any) ' szEntryid ID of server ' ' Note: In order for this example to function correctly, it may be necessary to include ' references to the following libraries: Active DS Type Library, Microsoft CDO for ' Exchange Management Library, Microsoft Cluster Service Automation Classes, ' Microsoft CDO for Windows 2000 Library. '////////////////////////////////////////////////////////////////////// Public Function getEntryIDfromName(ByVal szDomainName As String, _ ByVal szOrganizationName As String, _ ByVal szAdministrativeGroupName As String, _ ByVal szServerName As String, _ ByVal szVirtualServerName As String, _ ByVal szUserName As String, _ ByVal szUserPwd As String, _ ByRef szEntryID As String, _ ByVal szDirectoryServer) As Integer Dim objLdap As IADsOpenDSObject Dim objHosting As IADsContainer Dim objObject As IADs Dim iEntryIDNum As Integer Dim szConnString As String Dim iCounter As Integer Dim szaDomTokens() As String Dim szDomainDN As String Dim szStrippedServerName As String On Error GoTo errhandler ' Put the domain name into an ldap string. szaDomTokens = Split(szDomainName, ".", -1, 1) szDomainDN = Join(szaDomTokens, ",dc=") szDomainDN = "dc=" & szDomainDN ' If the value of szServerName has the server name at the end, it must be removed. ' For example, szServerName contained "www.fourthcoffee.com (calhost12)", "(calhost12)" must ' be removed from the string. ' Assumptions: only the server name will exist with a (), no other occurrances of () will ' exist in the string and ) will be the end of the string iCounter = InStr(szServerName, "(") If iCounter <> 0 Then szServerName = Mid(szServerName, 1, iCounter - 1) szServerName = Trim(szServerName) End If ' Build up the connection string. szConnString = "LDAP://" + szDirectoryServer + "/cn=http,cn=protocols,cn=" + _ szServerName + ",cn=servers,cn=" + szAdministrativeGroupName + _ ",cn=Administrative Groups,cn=" + szOrganizationName + _ ",cn=Microsoft Exchange,cn=services,cn=configuration," + _ szDomainDN ' Open up the directory with the passed credentials (preferably the admin). Set objLdap = GetObject("LDAP:") ' Get a container object from the connection string. Set objHosting = objLdap.OpenDSObject(szConnString, _ szUserName, _ szUserPwd, _ ADS_SECURE_AUTHENTICATION) ' Enumerate though each http server installed and get the highest entry id. iEntryIDNum = 0 objHosting.filter = Array("protocolCfgHTTPServer") For Each objObject In objHosting ' Assumptions: only the server name will exist with a (), no other occurrances of () will ' exist in the string and ) will be the end of the string szStrippedServerName = UCase(objObject.Get("adminDisplayName")) iCounter = InStr(szStrippedServerName, "(") If iCounter <> 0 Then szStrippedServerName = Mid(szStrippedServerName, 1, iCounter - 1) szStrippedServerName = Trim(szStrippedServerName) End If If UCase(szVirtualServerName) = szStrippedServerName Then iEntryIDNum = Int(Val(Mid(objObject.Name, 4))) End If Next szEntryID = Trim(Str(iEntryIDNum)) If iEntryIDNum = 0 Then getEntryIDfromName = 1 Else getEntryIDfromName = 0 End If ' Clean up. Set objLdap = Nothing Set objHosting = Nothing Set objObject = Nothing Exit Function ' Error handling. errhandler: getEntryIDfromName = 1 Set objLdap = Nothing Set objHosting = Nothing Set objObject = Nothing ' Implement error logging here. Exit Function End Function
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.