【问题标题】:How to convert this LDAP code from VBS to C++如何将此 LDAP 代码从 VBS 转换为 C++
【发布时间】:2012-11-12 03:32:38
【问题描述】:

我正在尝试编写 C++ 代码来枚举当前工作站在 Active Directory 设置中所属的组。我能够想出以下 Visual Basic 脚本,它完全符合我的需要:

'DN for the workstation
cCN = "CN=WorkstationName,CN=Computers,DC=mydomain,DC=local"
Set objComputer=GetObject("LDAP://" & cCN)

Dim strAll
Dim colGroups, objGroup

strAll = ""
Set colGroups = objComputer.Groups
For Each objGroup In colGroups
    strAll = strAll & objGroup.distinguishedName & vbLf
Next

Wscript.Echo strAll

我收到这样的输出:

CN=Group1,OU=SomeOU,DC=mydomain,DC=local
CN=Group2,OU=SomeOU,DC=mydomain,DC=local

问题是我似乎无法将 LDAP 内容转换为 C++。

如果有人可以帮助我,我将不胜感激?

编辑: 以下是我从我的 C++ 知识和 COM 中收集到的尽可能多的内容:

// Initialize COM.
CoInitialize(NULL);

LPCTSTR pwszContainerDN = L"CN=WorkstationName,CN=Computers,DC=mydomain,DC=local";

CComBSTR strADsPath = L"LDAP://";
strADsPath += pwszContainerDN;

IADs *objComputer;
HRESULT hr;

hr = ADsGetObject(strADsPath,
    IID_IADs,
    (void**) &objComputer);

if(SUCCEEDED(hr))
{
    //Now how do you do "objComputer.Groups"?
    //Then later "For Each" enumeration, etc.?
}

// Uninitialize COM.
CoUninitialize();

【问题讨论】:

    标签: c++ winapi vbscript active-directory ldap


    【解决方案1】:

    您也可以使用 WinLDAP 库。看到这个LDAP Search with winldap.h on AD Server

    【讨论】:

    • 如果你这样绑定,你将使用当前用户身份:ldap_bind_s(ldap, NULL, NULL, LDAP_AUTH_NEGOTIATE)
    猜你喜欢
    • 2011-11-17
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-26
    相关资源
    最近更新 更多