Mailbox FolderSize Problems
Exchange Server Forum Index Exchange Server
Discussion forums for Microsoft Exchange Server users.
Microsoft Outlook
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web ExchangeServerHelp.com
Mailbox FolderSize Problems

 
Post new topic   Reply to topic    Exchange Server Forum Index -> Development
Author Message
Barry
Guest





Posted: Wed Aug 24, 2005 4:38 pm    Post subject: Mailbox FolderSize Problems Reply with quote

Hi

I tried to get the folder size using the code snippet in
Microsoft's KB, it seem to work for "Administrator" only, is a user name
and password a must for the following code



#include "stdafx.h"
#include <activeds.h>

#import "c:\program files\common files\system\ado\msado15.dll"
no_namespace rename("EOF","adoEOF")
#import "c:\program files\common files\microsoft shared\cdo\cdoex.dll"
no_namespace

void StartUp();


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

int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);

StartUp();

CoUninitialize();

return 0;
}


void StartUp()
{
HRESULT hr = S_OK;
BSTR bstrDomainDNSName;

CoInitialize(NULL);

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


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

_bstr_t szConnString = "file://./backofficestorage/" +
(_bstr_t)bstrDomainName +
"/MBX/" +
bstrMailboxName;

_bstr_t szSQL = "Select ";
szSQL = szSQL +
"\"http://schemas.microsoft.com/exchange/foldersize\"";
szSQL = szSQL + ", \"DAV:displayname\"";
szSQL = szSQL + " from scope ('shallow traversal of ";
szSQL = szSQL + "\"" + szConnString + "\"" + "')";
szSQL = szSQL + " WHERE \"DAV:isfolder\" = true";

try {
_ConnectionPtr pConn(_uuidof(Connection));
_RecordsetPtr pRs(_uuidof(Recordset));

pConn->Provider = "Exoledb.DataSource";

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

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

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

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

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

while (VARIANT_FALSE == pRs->adoEOF)
{
FieldsPtr Flds = pRs->GetFields();
FieldPtr Fld = Flds->GetItem("DAV:displayname");
printf("Folder Name: %s\n", (char *)(_bstr_t)(Fld->Value));

Fld =
Flds->GetItem("http://schemas.microsoft.com/exchange/foldersize");
printf("Folder Size: %ld\n\n", (long)Fld->Value);
size = size + (long)Fld->Value;

pRs->MoveNext();
}

printf("Total Mailbox size: %ld\n\n", size);

hr = pRs->Close();
hr = pConn->Close();

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

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

CoUninitialize();
}


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;
}


TIA
Barry

Back to top
 
Post new topic   Reply to topic    Exchange Server Forum Index -> Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server Dedicated Servers
Contact Us
New Topics Powered by phpBB