How to convert this LDAP code from VBS to C++

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px Im 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. I was able to come up with the
following VB Script that does exactly what I need:
<pre class="prettyprint lang-vb 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[/code]
<br/>
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px and I receive the output as such:
<pre class="x_default x_prettyprint x_prettyprinted" style="padding:5px; border:0px; font-size:14px; vertical-align:baseline; background-color:#eeeeee; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif; width:auto; max-height:600px <code style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif <span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent CN<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 =<span class="typ" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#2b91af Group1<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 ,<span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent OU<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 =<span class="typ" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#2b91af SomeOU<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 ,<span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent DC<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 =<span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent mydomain<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 ,<span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent DC<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 =<span class="kwd" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#00008b local<span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent
CN<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 =<span class="typ" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#2b91af Group2<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 ,<span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent OU<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 =<span class="typ" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#2b91af SomeOU<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 ,<span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent DC<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 =<span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent mydomain<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 ,<span class="pln" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent DC<span class="pun" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#000000 =<span class="kwd" style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:#00008b local[/code][/code]
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px <br/>
The issue is that I cant seem to convert the LDAP stuff to C++.<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
Id really appreciate if someone can help me out?
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
<em style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif The following is as much as I can glean from my C++ knowledge and COM:[/i]
<pre class="prettyprint // 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();[/code]
<br/>
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif
<em style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif [/i]
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px

View the full article
 
Back
Top