Programming
No. | 404 |
Name. | swindler |
Subject. | C++에서 ADO로 Exchange 2000 Server 사서함 크기 확인 |
Main Cate. | Win32 |
Sub Cate. | |
Date. | 2007-11-23 16:27 |
Hit. | 3846 (211.36.27.8) |
File. | |
1. Win32 콘솔 응용 프로그램 마법사를 사용하여 일반 프로젝트를 새로 만들고 이름을 GetFolderSize로 지정합니다. 2. GetFolderSize.cpp를 엽니다. #include "stdafx.h" 위 코드 다음에 아래의 코드를 붙여넣고 main 함수를 바꿉니다. // You need to link with Activeds.lib and Adsiid.lib. #include <activeds.h> #include <stdio.h> #define IMPORTOPTS no_namespace rename("EOF", "adoEOF") #import "c:\program files\common files\system\ado\msado15.dll" 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 "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; } } 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; } 3. Project 메뉴에서 Settings를 클릭한 다음 Link 탭을 클릭합니다. Object/Library Modules에서 Activeds.lib와 Adsiid.lib를 추가합니다. 4. 프로젝트를 컴파일하고 빌드합니다. [바로가기 링크] : http://coolx.net/cboard/develop/404 |
|
|
|
[Modify] [Delete] | [Reply] [List] |