Share via


Getting a List of All Installed HTTP Virtual Servers

Getting a List of All Installed HTTP Virtual Servers

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 a list of all HTTP virtual servers on the specified server.

Visual Basic

'//////////////////////////////////////////////////////////////////////
' Function: getInstalledVirtualServerList()
' Purpose:  Returns a list of all virtual servers on specified server.
'
' Input:    szDomainName:               Domain of the Exchange organization
'           szOrganizationName:         Name of Exchange Organization
'           szAdministrativeGroupName:  Name of Administrative Group
'           szServerName:               Name of server to look at
'           szUserName:                 Admin Username
'           szUserPwd:                  Admin pwd
'           szDirectoryServer:          Name of the Directory Server
'
' Output:   getInstalledServerList:     Contains Error code (if any)
'           szServerList:               List of servers
'
' 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 getInstalledVirtualServerList(szDomainName As String, _
                                              szOrganizationName As String, _
                                              szAdministrativeGroupName As String, _
                                              szServerName As String, _
                                              szUserName As String, _
                                              szUserPwd As String, _
                                              szServerList As String, _
                                              ByVal szDirectoryServer) As Integer

    Dim objLdap As IADsOpenDSObject
    Dim objHosting As IADsContainer
    Dim objObject As IADs
    Dim szConnString As String
    Dim szaDomTokens() As String
    Dim szDomainDN 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

    ' Build up the ldap 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 passed credentials.

    Set objLdap = GetObject("LDAP:")

    ' Get a container object from the connection string.

    Set objHosting = objLdap.OpenDSObject(szConnString, _
                                          szUserName, _
                                          szUserPwd, _
                                          ADS_SECURE_AUTHENTICATION)

    ' Enumerate through each server object and get it's name.
    ' We can't use the getobjects function here since we are looking
    ' specifically for the adminDisplayName and not the DS name.

    szServerList = ""
    objHosting.filter = Array("protocolCfgHTTPServer")
    For Each objObject In objHosting
        If szServerList <> "" Then
            szServerList = szServerList + ";" + objObject.Get("adminDisplayName")
        Else
            szServerList = objObject.Get("adminDisplayName")
        End If
    Next

    If szServerList = "" Then
        szServerList = "No virtual servers"
    End If

    szServerList = UCase(szServerList)


    getInstalledVirtualServerList = 0

    ' Clean up.
    Set objLdap = Nothing
    Set objHosting = Nothing
    Set objObject = Nothing
    Exit Function

    ' Error handling.
errhandler:

    szServerList = "Couldn't retrieve list of servers"
    getInstalledVirtualServerList = 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.