Microsoft KB Archive/291368

= How To Determine the Size of Exchange 2000 Server Mailbox with ADO in C++ =

Article ID: 291368

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft ActiveX Data Objects 2.5

-



This article was previously published under Q291368



SUMMARY
This article provides a Microsoft Visual C++ (VC) code sample that demonstrates how to use ActiveX Data Objects (ADO) to determine the size of a user's mailbox.



MORE INFORMATION
To determine the size of the mailbox, follow these steps:  With the Win32 Console Application AppWizard, create a new Simple project and name it GetFolderSize.  Open GetFolderSize.cpp. Paste the following code after and replace the main function. // You need to link with Activeds.lib and Adsiid.lib.
 * 1) include &quot;stdafx.h&quot;


 * 1) include 
 * 2) include 


 * 1) define IMPORTOPTS no_namespace rename(&quot;EOF&quot;, &quot;adoEOF&quot;)
 * 2) import &quot;c:\program files\common files\system\ado\msado15.dll&quot; IMPORTOPTS

HRESULT GetDomainName(BSTR * bstrDomainName); HRESULT GetMailboxSize(BSTR bstrDomainName, BSTR bstrMailboxname);

struct StartOle { StartOle { CoInitialize(NULL); } ~StartOle { CoUninitialize; } } _inst_StartOle;

void main {  HRESULT hr = S_OK; BSTR   bstrDomainDNSName;

hr = GetDomainName(&bstrDomainDNSName); // try to find out &quot;Administrator&quot; mailbox size hr = GetMailboxSize(bstrDomainDNSName, L&quot;administrator&quot;); }

HRESULT GetMailboxSize(BSTR bstrDomainName, BSTR bstrMailboxName) {  HRESULT hr = S_OK; long  size = 0;

_bstr_t szConnString = &quot;file://./backofficestorage/&quot; + (_bstr_t)bstrDomainName + &quot;/MBX/&quot; + bstrMailboxName; _bstr_t szSQL = &quot;Select &quot;; szSQL = szSQL + &quot;\&quot;http://schemas.microsoft.com/exchange/foldersize\&quot;&quot;; szSQL = szSQL + &quot;, \&quot;DAV:displayname\&quot;&quot;; szSQL = szSQL + &quot; from scope ('shallow traversal of &quot;;  szSQL = szSQL + &quot;\&quot;&quot; + szConnString + &quot;\&quot;&quot; + &quot;')&quot;; szSQL = szSQL + &quot; WHERE \&quot;DAV:isfolder\&quot; = true&quot;; try { _ConnectionPtr  pConn(_uuidof(Connection)); _RecordsetPtr  pRs(_uuidof(Recordset));

pConn->Provider = &quot;Exoledb.DataSource&quot;;

hr = pConn->Open(szConnString, &quot;&quot;, &quot;&quot;, 0);

if (pConn->State == adStateOpen) printf(&quot;Connection Opened\n&quot;); else {        printf(&quot;Connection Failed\n&quot;); return hr; }

hr = pRs->Open(szSQL,         pConn->ConnectionString,         adOpenForwardOnly,         adLockReadOnly,         0);

// Determine if any folders were found. if (pRs->RecordCount == 0) {         printf(&quot;No object found\n&quot;); return hr; }

// Move to the first folder. hr = pRs->MoveFirst;

while (VARIANT_FALSE == pRs->adoEOF) {                           FieldsPtr Flds = pRs->GetFields; FieldPtr Fld = Flds->GetItem(&quot;DAV:displayname&quot;); printf(&quot;Folder Name: %s\n&quot;, (char *)(_bstr_t)(Fld->Value)); Fld = Flds->GetItem(              &quot;http://schemas.microsoft.com/exchange/foldersize&quot;); printf(&quot;Folder Size: %ld\n\n&quot;, (long)Fld->Value); size = size + (long)Fld->Value; pRs->MoveNext; }

printf(&quot;Total Mailbox size: %ld\n\n&quot;, size); hr = pRs->Close; hr = pConn->Close;

if (FAILED(hr)) {        printf(&quot;Close Connection Failed\n&quot;); return hr; }     else printf(&quot;Connection Closed\n\n&quot;); return hr;

}  catch(_com_error e)   { printf(&quot;HResult = %x\n&quot;, e.Error); printf(&quot;%S\n&quot;, e.Description); return hr; } }

HRESULT GetDomainName(BSTR * bstrDomainName) {  HRESULT hr = S_OK; IADsADSystemInfo *pADsys;

hr = CoCreateInstance(CLSID_ADSystemInfo,            NULL,             CLSCTX_INPROC_SERVER,             IID_IADsADSystemInfo,             (void**)&pADsys);

hr = pADsys->get_DomainDNSName(bstrDomainName); if (pADsys) pADsys->Release; return hr; }                    On the Project menu, click Settings, and then click the Link tab. In Object/Library Modules, add Activeds.lib and Adsiid.lib. Compile and build the project.

Additional query words: ADO size mailbox

Keywords: kbhowto kbmsg KB291368

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.