简体   繁体   English

如何将此 LDAP 代码从 VBS 转换为 C++

[英]How to convert this LDAP code from VBS to C++

I'm trying to come up with a C++ code to enumerate groups that the current workstation is a member of in an Active Directory set-up.我试图想出一个 C++ 代码来枚举当前工作站是 Active Directory 设置中的成员的组。 I was able to come up with the following Visual Basic script that does exactly what I need:我能够想出以下 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

and I receive the output as such:我收到这样的输出:

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

The issue is that I can't seem to convert the LDAP stuff to C++.问题是我似乎无法将 LDAP 内容转换为 C++。

I'd really appreciate if someone can help me out?如果有人可以帮助我,我真的很感激?

EDIT: The following is as much as I can glean from my C++ knowledge and COM:编辑:以下是我从我的 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();

此Microsoft链接向您显示所需的一切示例代码用于枚举本地组

You can also use WinLDAP library. 您也可以使用WinLDAP库。 See this LDAP Search with winldap.h on AD Server . 在AD Server上使用winldap.h查看此LDAP搜索

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM