What i also need to do is for each exchange server in the list i need
to create and IExchangeServer object so that i can access it's storage
groups etc. I have seen many examples of this in VB, but i am doing
this using VC++.. has anybody done this in VC++.
Here is some of my code;
IADs *pADs = NULL;
IDirectorySearch *pDirSrch = NULL;
LPOLESTR szPath = new OLECHAR[MAX_PATH];
VARIANT var;
hr = ADsOpenObject(L"LDAP://rootDSE",
NULL,
NULL,
// Use secure authentication.
ADS_SECURE_AUTHENTICATION,
IID_IADs,
(void**)&pADs);
if (FAILED(hr))
{
wprintf(L"Not Found. Could not bind to the domain.\n");
if (pADs)
pADs->Release();
return hr;
}
hr = pADs->Get(L"configurationNamingContext",&var);
if (SUCCEEDED(hr))
{
wcscpy(szPath,L"LDAP://");
wcscat(szPath,var.bstrVal);
VariantClear(&var);
printf("path %s:\n", szPath);
// Bind to the root of the configuration context.
hr = ADsOpenObject(szPath,
NULL,
NULL,
// Use secure authentication.
ADS_SECURE_AUTHENTICATION,
IID_IDirectorySearch,
(void**)&pDirSrch);
wprintf(L"path %s:\n", szPath);
if (SUCCEEDED(hr))
{
HRESULT hr = E_FAIL;
// Create the search filter.
LPOLESTR pszSearchFilter = new OLECHAR[MAX_PATH];
LPOLESTR szADsPath = new OLECHAR[MAX_PATH];
wcscpy(pszSearchFilter,
L"(&(objectCategory=msExchExchangeServer)(objectClass=msExchExchangeServer))");
// Search the entire subtree from the root.
ADS_SEARCHPREF_INFO pSearchPrefs;
pSearchPrefs.dwSearchPref = ADS_SEARCHPREF_SEARCH_SCOPE;
pSearchPrefs.vValue.dwType = ADSTYPE_INTEGER;
pSearchPrefs.vValue.Integer = ADS_SCOPE_SUBTREE;
DWORD dwNumPrefs = 1;
// Handle used for searching
ADS_SEARCH_HANDLE hSearch;
// Set the search preference.
hr = pDirSrch->SetSearchPreference( &pSearchPrefs, dwNumPrefs);
if (FAILED(hr))
return hr;
// Set attributes to return.
CONST DWORD dwAttrNameSize = 1;
LPOLESTR pszAttribute[dwAttrNameSize] = {L"ADsPath"};
// Execute the search.
hr = pDirSrch->ExecuteSearch(pszSearchFilter,
NULL, //pszAttribute,
-1, //dwAttrNameSize,
&hSearch);
if (SUCCEEDED(hr))
{
//pDirSrch->GetFirstRow( hSearch );
for( hr = pDirSrch->GetFirstRow( hSearch );
SUCCEEDED( hr ) && hr != S_ADS_NOMORE_ROWS;
hr = pDirSrch->GetNextRow( hSearch ) )
{
for (DWORD x = 0; x < dwAttrNameSize; x++)
{
LPWSTR pszColumn = L"cn";
ADS_SEARCH_COLUMN col;
// Get the data for this column.
hr = pDirSrch->GetColumn( hSearch, pszColumn, &col );
//hr = pDirSrch->GetColumn( hSearch, pszColumn, &col );
if( SUCCEEDED( hr ) )
{
wprintf(L"Column Name is: %s\n", pszColumn);
wprintf(L"cn is: %s\n",col.pADsValues->CaseIgnoreString);
hr = pDirSrch->GetColumn(hSearch, L"ADsPath", &col);
wprintf(L"ADsPath is: %s\n",col.pADsValues->CaseIgnoreString);
if (FAILED(hr))
{
wprintf(L"Failed to get value for ADsPath");
return hr;
}
IADs *pADs;
IExchangeServer *pES = NULL;
hr = ADsGetObject(col.pADsValues->CaseIgnoreString,
IID_IADs,
(void**) &pADs );
/*** HERE I WOULD LIKE TO SOMEHOW CAST THE pADs object or an
IDirectoryObject (if i were to use this instead of IADs) TO AN
EXCHANGE OBJECT (IExchangeObject) - DOES ANYONE HAVE ANY IDEA HOW I
COULD DO THIS?? ***/
if ( !SUCCEEDED(hr) )
{
wprintf(L"Get object failed\n");
return hr;
}
else
{
wprintf(L"Get object Successful\n");
BSTR retVal = L"";
//hr = pES->get_Name(&name);
hr = pADs->get_Class(&retVal);
if (SUCCEEDED(hr))
{
wprintf(L"Ret Val: %s\n", retVal);
}
else
{
wprintf(L"get retVal failed");
return hr;
}
}
if (pADs)
{
pADs->Release();
pADs = NULL;
}
if (pES)
{
pES->Release();
pES = NULL;
}
}
( void )pDirSrch->FreeColumn( &col );
}
}
}
// Close the search handle to clean up.
pDirSrch->CloseSearchHandle(hSearch);
//pDirSrch->FreeColumn( &col );
}
}
if (pADs)
{
pADs->Release();
pADs = NULL;
}
if (pDirSrch)
{
pDirSrch->Release();
pDirSrch = NULL;
}
Thanks in Advance..!!!
joe
--
Joe Richards Microsoft MVP Windows Server Directory Services
www.joeware.net
"Joe Richards [MVP]" <humore...@hotmail.com> wrote in message news:<OBc1P5zP...@TK2MSFTNGP11.phx.gbl>...
Note that public folders you won't be able to get with LDAP if they are not
mail-enabled. To get all existing public folder in a particular public store
you need to use ADO/ExOLEDB or XML & WebDAV to query that particular public
store directly.
--
Cheers,
Siegfried Weber
If you want a smart answer, ask a smart question
http://catb.org/~esr/faqs/smart-questions.html
Why tables are bad: http://www.hotdesign.com/seybold/,
http://webdesign.about.com/cs/tables/a/aa020800b.htm
Note: Please do not send any e-mail to my old address
swe...@cdolive.com because I am no longer connected with this
organization.
"rp" <rimpl...@hotmail.com> a écrit dans le message de
news:f5953cae.04052...@posting.google.com...