Getting the Next Available Recipient Policy Order Number
Getting the Next Available Recipient Policy Order Number
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 gets the next available recipient policy order number.
Visual Basic
'////////////////////////////////////////////////////////////////////// ' Function: getNextAvailableRecipientPolicyOrderNumber() ' Purpose: Gets the next available recipient policy order number. ' ' Input: szDomainName: Domain of the Exchange organization ' szOrganizationName: Name of the Exchange organization ' szUserName: Admin username ' szUserPwd: Admin pwd ' iPolicyOrder: Next available policy number ' szDirectoryServer: Name of the Directory Server ' ' Output: getNextAvailableRecipientPolicyOrderNumber: 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 getNextAvailableRecipientPolicyOrderNumber(ByVal szDomainName As String, _ ByVal szOrganizationName As String, _ ByVal szUserName As String, _ ByVal szUserPwd As String, _ ByRef szPolicyOrder As String, _ ByVal szDirectoryServer) As Integer Dim objLdap As IADsOpenDSObject Dim objPolicy As IADsContainer Dim objObject As IADs Dim iEntryIDNum As Integer 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 connection string. szConnString = "LDAP://" + szDirectoryServer + "/" + _ "cn=Recipient Policies,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 objPolicy = objLdap.OpenDSObject(szConnString, _ szUserName, _ szUserPwd, _ ADS_SECURE_AUTHENTICATION) ' Initialize iEntryIDNim to 1. iEntryIDNum = 1 objPolicy.filter = Array("msExchRecipientPolicy") For Each objObject In objPolicy If iEntryIDNum <= Int(Val(objObject.Get("msExchPolicyOrder"))) Then If Int(Val(objObject.Get("msExchPolicyOrder"))) <> 2147483647 Then iEntryIDNum = Int(Val(objObject.Get("msExchPolicyOrder"))) + 1 End If End If Next szPolicyOrder = Str(iEntryIDNum) getNextAvailableRecipientPolicyOrderNumber = 0 ' Clean up. Set objLdap = Nothing Set objPolicy = Nothing Set objObject = Nothing Exit Function ' Error handling. errhandler: szPolicyOrder = Str(-1) getNextAvailableRecipientPolicyOrderNumber = 1 ' Implement error logging here. Set objLdap = Nothing Set objPolicy = Nothing Set objObject = Nothing 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.