Share via


Verifying the Existence of a Hosting Container

Verifying the Existence of a Hosting Container

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 verifies the existence of a hosting container.

Visual Basic

'//////////////////////////////////////////////////////////////////////
' Function: checkHostingContainer()
' Purpose:  Verifies the existence of a hosting container.
'
' Input:    szDomainName:         Domain of the Exchange organization
'           szHostingName:        Name of hosting folder in the DS
'           szUserName:           Admin Username
'           szUserPwd:            Admin pwd
'           szDirectoryServer:    Directory Server name
'
' Output:   checkHostingContainer:        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 checkHostingContainer(ByVal szDomainName As String, _
                                      ByVal szHostingName As String, _
                                      ByVal szUserName As String, _
                                      ByVal szUserPwd As String, _
                                      ByVal szDirectoryServer) As Integer

' Does the hosting container exist?

    Dim objLdap As IADsOpenDSObject
    Dim objHosting As IADsContainer
    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 the ldap connection string.

    szConnString = "LDAP://" + szDirectoryServer + "/ou=" + _
                   szHostingName + "," + szDomainDN


    ' Open up the directory with the passed credentials (preferably the admin).

    Set objLdap = GetObject("LDAP:")

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

    checkHostingContainer = 0

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

    ' Error handling.
errhandler:

    If InStr(Err.Description, "There is no such object") Then
        checkHostingContainer = 1
    Else
        checkHostingContainer = 2
    End If

    'Implement error logging here.
    Set objHosting = Nothing
    Set objLdap = Nothing

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.