Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exchange Server Object

4 views
Skip to first unread message

rp

unread,
May 20, 2004, 8:07:42 PM5/20/04
to
I'm using adsi to query the active directory and get a list of
exchange servers, this works perfectly well.

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 Richards [MVP]

unread,
May 21, 2004, 10:19:01 AM5/21/04
to
I don't do ADSI in c/c++ but I am curious what your final goal is, what info are
you trying to get, it is possible you don't need to use anything but LDAP to get
it.

joe

--
Joe Richards Microsoft MVP Windows Server Directory Services
www.joeware.net

rp

unread,
May 21, 2004, 1:47:24 PM5/21/04
to
I'm trying to get an Exchange server object in order to obtain a list
of it's storage groups, and the storage group Mailbox stores and
public folders etc.
I'm basically trying to build a tree with Exchange server->storage
groups->Mailboxes and public folders.


"Joe Richards [MVP]" <humore...@hotmail.com> wrote in message news:<OBc1P5zP...@TK2MSFTNGP11.phx.gbl>...

Siegfried Weber

unread,
May 21, 2004, 5:28:19 PM5/21/04
to
rp wrote:
>
> I'm trying to get an Exchange server object in order to obtain a list
> of it's storage groups, and the storage group Mailbox stores and
> public folders etc.
> I'm basically trying to build a tree with Exchange server->storage
> groups->Mailboxes and public folders.

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.

Israel Prince-Beliveau

unread,
Jun 3, 2004, 1:47:54 PM6/3/04
to
Does anyone know how I could do that in c# ?

"rp" <rimpl...@hotmail.com> a écrit dans le message de
news:f5953cae.04052...@posting.google.com...

0 new messages