簡體   English   中英

如何將此 LDAP 代碼從 VBS 轉換為 C++

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

我試圖想出一個 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();

此Microsoft鏈接向您顯示所需的一切示例代碼用於枚舉本地組

您也可以使用WinLDAP庫。 在AD Server上使用winldap.h查看此LDAP搜索

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM