首页 > 其他 > 详细

AD使用adsi 组件 获取域信息

时间:2019-05-19 14:59:37      阅读:202      评论:0      收藏:0      [点我收藏+]

// 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;
}

 

AD使用adsi 组件 获取域信息

原文:https://www.cnblogs.com/hshy/p/10889188.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!