AD使用adsi 组件 获取域信息
作者:互联网
// testadsi.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "windows.h"
#include "activeds.h"
#include <atlbase.h>
#pragma comment(lib,"Activeds.lib")
#pragma comment(lib,"adsiid.lib")
#pragma comment(lib,"comsuppw.lib")
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr;
IADsContainer *pCont;
IDispatch *pDisp = NULL;
IADs *pUser;
// Initialize COM before calling any ADSI functions or interfaces.
CoInitialize(NULL);
hr = ADsGetObject(L"LDAP://CN=users,DC=fabrikam,DC=com",
IID_IADsContainer,
(void**)&pCont);
if (!SUCCEEDED(hr))
{
return 0;
}
//-----------------
// Create a user
//-----------------
hr = pCont->Create(CComBSTR("user"), CComBSTR("jeffsmith"), &pDisp);
// Release the container object.
pCont->Release();
if (!SUCCEEDED(hr))
{
return 0;
}
hr = pDisp->QueryInterface(IID_IADs, (void**)&pUser);
// Release the dispatch interface.
pDisp->Release();
if (!SUCCEEDED(hr))
{
return 0;
}
// Commit the object data to the directory.
pUser->SetInfo();
// Release the object.
pUser->Release();
CoUninitialize();
return 0;
}
标签:return,AD,lib,pDisp,hr,Release,组件,include,adsi 来源: https://www.cnblogs.com/hshy/p/10889188.html