Алексей1153++ - я ее заблокировал. Сразу после поста. Ну а ты перенес заблокированной.
Собственно ларчик просто открывается. Начиная с w2k в каждой системе есть поддержка интерфейсов Active Directory, в том числе и диалоги выбора пользователей, компьютеров и т.д.. Причем вызовы функций NetXXX в конечном итоге обращаются именно к этим интерфейсам (Рихтер). Ниже пример из MSDN открывающий диалог выбора компьютера. Изменив пару фильтров можно достичь ответ на вопрос этой темы.
#include <objsel.h>
HRESULT InitObjectPicker(IDsObjectPicker *pDsObjectPicker);
HRESULT ProcessSelectedObjects(IDataObject *pdo);
/**************************************************************************
main()
**************************************************************************/
void main(void)
{
HRESULT hr = S_OK;
IDsObjectPicker *pDsObjectPicker = NULL;
IDataObject *pdo = NULL;
hr = CoInitialize(NULL);
if(FAILED(hr))
{
return;
}
// Create an instance of the object picker.
hr = CoCreateInstance( CLSID_DsObjectPicker,
NULL,
CLSCTX_INPROC_SERVER,
IID_IDsObjectPicker,
(void**) &pDsObjectPicker);
if(SUCCEEDED(hr))
{
// Initialize the object picker instance.
hr = InitObjectPicker(pDsObjectPicker);
if(SUCCEEDED(hr))
{
HWND hwndParent = GetConsoleWindow(); // Supply a window handle to the application.
// Invoke the modal dialog box.
hr = pDsObjectPicker->InvokeDialog(hwndParent, &pdo);
if (hr == S_OK)
{
ProcessSelectedObjects(pdo);
pdo->Release();
}
else if (hr == S_FALSE)
{
printf("User canceled object picker dialog\n");
}
}
}
pDsObjectPicker->Release();
CoUninitialize();
printf("\nPress <enter> to exit:");
getchar();
}
/**************************************************************************
InitObjectPicker()
**************************************************************************/
HRESULT InitObjectPicker(IDsObjectPicker *pDsObjectPicker)
{
if(NULL == pDsObjectPicker)
{
return E_INVALIDARG;
}
DSOP_SCOPE_INIT_INFO aScopeInit[1];
DSOP_INIT_INFO InitInfo;
// Initialize the DSOP_SCOPE_INIT_INFO array.
ZeroMemory(aScopeInit, sizeof(aScopeInit));
// Combine multiple scope types in a single array entry.
aScopeInit[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
aScopeInit[0].flType = DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
| DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN;
// Set up-level and down-level filters to include only computer objects.
// Up-level filters apply to both mixed and native modes.
// Be aware that the up-level and down-level flags are different.
aScopeInit[0].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
aScopeInit[0].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS;
// Initialize the DSOP_INIT_INFO structure.
ZeroMemory(&InitInfo, sizeof(InitInfo));
InitInfo.cbSize = sizeof(InitInfo);
InitInfo.pwzTargetComputer = NULL; // Target is the local computer.
InitInfo.cDsScopeInfos = sizeof(aScopeInit)/sizeof(DSOP_SCOPE_INIT_INFO);
InitInfo.aDsScopeInfos = aScopeInit;
InitInfo.flOptions = DSOP_FLAG_MULTISELECT;
// Initialize can be called multiple times, but only the last call has effect.
// Be aware that object picker makes its own copy of InitInfo.
return pDsObjectPicker->Initialize(&InitInfo);
}
/**************************************************************************
ProcessSelectedObjects()
**************************************************************************/
HRESULT ProcessSelectedObjects(IDataObject *pdo)
{
if(NULL == pdo)
{
return E_INVALIDARG;
}
HRESULT hr;
STGMEDIUM stm;
FORMATETC fe;
// Get the global memory block that contain the user's selections.
fe.cfFormat = RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST);
fe.ptd = NULL;
fe.dwAspect = DVASPECT_CONTENT;
fe.lindex = -1;
fe.tymed = TYMED_HGLOBAL;
hr = pdo->GetData(&fe, &stm);
if(SUCCEEDED(hr))
{
PDS_SELECTION_LIST pDsSelList = NULL;
// Retrieve a pointer to DS_SELECTION_LIST structure.
pDsSelList = (PDS_SELECTION_LIST)GlobalLock(stm.hGlobal);
if(NULL != pDsSelList)
{
ULONG i;
// Loop through DS_SELECTION array of selected objects.
for (i = 0; i < pDsSelList->cItems; i++)
{
printf("Object %u\n", i);
printf(" Name '%ws'\n",
pDsSelList->aDsSelection[i].pwzName);
printf(" Class '%ws'\n",
pDsSelList->aDsSelection[i].pwzClass);
printf(" Path '%ws'\n",
pDsSelList->aDsSelection[i].pwzADsPath);
printf(" UPN '%ws'\n",
pDsSelList->aDsSelection[i].pwzUPN);
}
GlobalUnlock(stm.hGlobal);
}
else
{
hr = E_POINTER;
}
ReleaseStgMedium(&stm);
}
return hr;
}