Microsoft KB Archive/200154

= How To Export Directory Information to a File Using BatchExport =

Article ID: 200154

Article Last Modified on 8/25/2005

-

APPLIES TO


 * Microsoft Messaging Application Programming Interface
 * Microsoft Exchange Development Kit 5.5
 * Microsoft Exchange Server 2003 Software Development Kit

-



This article was previously published under Q200154



SUMMARY
Exporting mailbox information about mailboxes on the messaging system may be required. You can do this programmatically using BatchExport and passing a few parameters. This article contains the code that demonstrates how to use BatchExport to write out the mailbox information for all users to the file Test.csv. The program takes two parameters: server and organization name.



MORE INFORMATION
The following code should be compiled as a console application using these libraries:


 * Mapi32.lib
 * Dapi.lib


 * 1) include 
 * 2) include 
 * 3) include 

void ReportDAPIEvent(DAPI_EVENT* pDAPIEvent);

void main(int argc, char* argv[])

{  HRESULT hr = 0; BEXPORT_PARMS   BexportParms    = {0}; LPBEXPORT_PARMS lpBexportParms = {0}; DAPI_HANDLE hDAPISession; DAPI_EVENT* pDAPIEvent = NULL; DAPI_PARMS DAPIParms = {0}; char szAccount[UNLEN + MAX_COMPUTERNAME_LENGTH + 2]; DWORD dwAccountLength = UNLEN + MAX_COMPUTERNAME_LENGTH + 1; if (2 > argc) { printf("\nDAPITest ExchangeServerName /O=Organization"); return; }  printf("\nExchange Server: %s", argv[1]); // start DAPI for this session //initialize the the DAPI Parms structure and the DAPI operation session DAPIParms.dwDAPISignature = DAPI_SIGNATURE; DAPIParms.dwFlags = DAPI_EVENT_ALL|DAPI_MODIFY_REPLACE_PROPERTIES|DAPI_RESTRICT_ACCESS ; DAPIParms.pszDSAName = argv[1]; DAPIParms.pszBasePoint = NULL; DAPIParms.pszContainer = NULL; DAPIParms.pszNTDomain = argv[1]; DAPIParms.pszCreateTemplate = NULL; DAPIParms.pAttributes = NULL; pDAPIEvent = DAPIStart(&hDAPISession, &DAPIParms); //struct with DAPI params if(pDAPIEvent) {       printf("\nDAPIStart ERROR %08x - check app eventlog", pDAPIEvent->dwDAPIError); ReportDAPIEvent(pDAPIEvent); }   else printf("\nDAPIStart was successful"); lpBexportParms = &BexportParms; lpBexportParms->dwDAPISignature = DAPI_SIGNATURE; lpBexportParms->dwFlags = DAPI_EXPORT_MAILBOX | DAPI_EXPORT_HIDDEN | DAPI_EVENT_ALL |DAPI_EXPORT_SUBTREE ; lpBexportParms->pszExportFile = "TEST.CSV"; lpBexportParms->pszBasePoint = argv[2]; lpBexportParms->pszDSAName = argv[1]; lpBexportParms->pszHomeServer = NULL; lpBexportParms->chColSep = DAPI_DEFAULT_DELIM; lpBexportParms->chQuote = DAPI_DEFAULT_QUOTE; lpBexportParms->chMVSep = DAPI_DEFAULT_MV_SEP; hr = BatchExport(lpBexportParms); DAPIEnd(&hDAPISession); printf("\nEND PROGRAM"); } void ReportDAPIEvent(DAPI_EVENT* pDAPIEvent) {   HANDLE hDAPIEventSource = RegisterEventSource(NULL, TEXT("MSExchangeDSImp")); ReportEvent(        hDAPIEventSource,         (WORD)EVENTLOG_ERROR_TYPE,         0,         pDAPIEvent->dwDAPIError,         NULL,         (WORD)pDAPIEvent->unSubst,         0,         pDAPIEvent->rgpszSubst,         NULL); DAPIFreeMemory(pDAPIEvent); DeregisterEventSource(hDAPIEventSource); )

}

