Creating an HTTP Virtual Directory

Creating an HTTP Virtual Directory

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 creates an HTTP virtual directory on a specified virtual server. This example uses a function for Determining If the Specified Server Is a Front-End Server.

Visual Basic

'//////////////////////////////////////////////////////////////////////
' Function: createHTTPVirtualDirectory()
' Purpose:  Creates an HTTP virtual directory on a specified virtual server.
'
' Input:    szDomainName:               Domain of the Exchange organization
'           szOrganizationName:         Name of Exchange Organization
'           szAdministrativeGroupName:  Name of Administrative Group
'           szServerName:               Name of server to use
'           szDefaultLogonDomain:       default logon domain setting
'           szVirtualDirectoryName:     Name for the virtual directory
'           szVirtualDirectoryPath:     Path for the virtual directory
'           szMsExchDefaultDomain:      Value for the msExchDefaultDomain property
'           szUserName:                 Admin Username
'           szUserPwd:                  Admin pwd
'           szDirectoryServer:          Name of the Directory Server
'
' Output:   createHTTPVirtualDirectory: Contains Error code (if any)
'
' 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 createHTTPVirtualDirectory(ByVal szDomainName As String, _
                                           ByVal szOrganizationName As String, _
                                           ByVal szAdministrativeGroupName As String, _
                                           ByVal szServerName As String, _
                                           ByVal szEntryID As String, _
                                           ByVal szDefaultLogonDomain As String, _
                                           ByVal szVirtualDirectoryName As String, _
                                           ByVal szVirtualDirectoryPath As String, _
                                           ByVal szMsExchDefaultDomain As String, _
                                           ByVal szUserName As String, _
                                           ByVal szUserPwd As String, _
                                           ByVal szDirectoryServer) As Integer

    Dim objLdap As IADsOpenDSObject
    Dim objHosting As IADsContainer
    Dim objHttpServerContainer As IADs
    Dim szConnString As String
    Dim bisFrontEnd As Boolean
    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

    ' Is this server a front end?  Needed later for the msExchServerRole property.

    isFrontEndServer szDomainName, _
                     szOrganizationName, _
                     szAdministrativeGroupName, _
                     szServerName, _
                     szUserName, _
                     szUserPwd, _
                     bisFrontEnd, _
                     szDirectoryServer

    ' Build the ldap connection string.

    szConnString = "LDAP://" + szDirectoryServer + "/cn=" + _
                   Trim(szEntryID) + ",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)

    ' Create the object hosting container.

    Set objHttpServerContainer = objHosting.Create("msExchProtocolCfgHTTPVirtualDirectory", _
                                                   "cn=" + szVirtualDirectoryName)

    ' Required properties.

    With objHttpServerContainer
        .Put "hTTPPubGAL", False
        .Put "systemFlags", 1610612736
        .Put "msExchAccessFlags", 19
        .Put "msExchAuthenticationFlags", 2
        .Put "msExchBasicAuthenticationDomain", szDefaultLogonDomain

        If InStr(szVirtualDirectoryPath, "MBX") Then
            .Put "msExchDefaultDomain", szMsExchDefaultDomain
        End If

        .Put "msExchDefaultLogonDomain", getTopLevelDomainName(szDomainName)
        .Put "msExchDirBrowseFlags", -1073741794
        .Put "msExchIncomingConnectionTimeout", 900
        .Put "msExchLogonMethod", 3
        .Put "msExchMaxIncomingConnections", 2000000000
        .Put "msExchServerAutoStart", True
        .Put "folderPathname", szVirtualDirectoryPath
        .Put "msExchLogType", 0

        If bisFrontEnd Then
            .Put "msExchServerRole", 1
        Else
            .Put "msExchServerRole", 0
        End If

        .SetInfo

    End With

    createHTTPVirtualDirectory = 0

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

    ' Error handling.
errhandler:

    Set objLdap = Nothing
    Set objHosting = Nothing
    Set objHttpServerContainer = Nothing

    createHTTPVirtualDirectory = 1
    ' 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.