Microsoft KB Archive/327079

= How to programmatically create a mailbox for an existing user in the Active Directory by using CDOEXM =

Article ID: 327079

Article Last Modified on 10/25/2007

-

APPLIES TO


 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft Exchange Server 2003 Enterprise Edition
 * Microsoft Exchange Server 2003 Standard Edition
 * Microsoft Active Directory Service Interfaces 2.5
 * Microsoft Active Directory Service Interfaces 2.5

-



This article was previously published under Q327079





INTRODUCTION
This article describes how to programmatically create a mailbox for an existing user in the Active Directory directory service by using the Microsoft Collaboration Data Objects for Exchange Management (CDOEXM) interfaces.



MORE INFORMATION
Some customers have encountered problems with the CreateMailbox function when they try to create mailboxes for existing users in Active Directory. These problems occur on servers that are running either Exchange 2000 Server or Exchange Server 2003. When they try to create mailboxes, they receive one of the following error messages:

Error -2147467259 There is no Connection Agreement configured to export this recipient to the Exchange 5.5 server.

ID no: c1034a1b Microsoft CDO for Exchange Management

Error -2147016646 The server is not operational Facility: Win32

ID no: 8007203a Microsoft CDO for Exchange Management

These customers have been able to work around this problem by binding explicitly to a domain controller.

Sample code
The following Microsoft VBScript sample code shows how to programmatically create a mailbox for an existing user by using CDOEXM. You must run this sample code on a computer that has the Microsoft Exchange System Manager Tools installed.  Create a domain user. However, do not create an Exchange mailbox for the domain user. Create a .vbs file  Add the following sample code to the .vbs file. Dim oIADSUser Dim oMailbox

Set oIADS = GetObject(&quot;LDAP://RootDSE&quot;) strDefaultNC = oIADS.Get(&quot;defaultnamingcontext&quot;) 'MsgBox FindAnyMDB(&quot;CN=Configuration,&quot; & strDefaultNC)

'TODO: Use the newly created domain user account to replace the &quot;UserName&quot;. Set oIADSUser = GetObject(&quot;LDAP://CN=UserName,CN=Users,&quot; & strDefaultNC)

If oIADSUser Is Nothing then MsgBox &quot;The oIADSUser is Nothing.&quot; Else MsgBox &quot;The oIADSUser is created successfully.&quot; End If

Set oMailBox = oIADSUser oMailbox.CreateMailbox FindAnyMDB(&quot;CN=Configuration,&quot; & strDefaultNC) oIADSUser.SetInfo

Function FindAnyMDB(strConfigurationNC) Dim oConnection Dim oCommand Dim oRecordSet Dim strQuery

' Open the Connection. Set oConnection = CreateObject(&quot;ADODB.Connection&quot;) set oCommand = CreateObject(&quot;ADODB.Command&quot;) Set oRecordSet = CreateObject(&quot;ADODB.Recordset&quot;)

oConnection.Provider = &quot;ADsDSOObject&quot; oConnection.Open &quot;ADs Provider&quot;

' Build the query to find the private MDB. strQuery = &quot;;(objectCategory=msExchPrivateMDB);name,adspath;subtree&quot;

oCommand.ActiveConnection = oConnection oCommand.CommandText = strQuery Set oRecordSet = oCommand.Execute

' If you have an MDB, return the first one. If Not oRecordSet.EOF Then oRecordSet.MoveFirst FindAnyMDB = CStr(oRecordSet.Fields(&quot;ADsPath&quot;).Value) Else FindAnyMDB = &quot;&quot; End If

'Clean up. oRecordSet.Close oConnection.Close Set oRecordSet = Nothing Set oCommand = Nothing Set oConnection = Nothing End Function  Search for the TODO text string in the code, and then modify the code for your environment. Run the sample code.</ol>

<div class="references_section">