EDN Admin
Well-known member
I have this piece of code, in C/C++.
<br/>
<br/>
IADs *pADsGUID,*pADs;<br/>
BSTR bstr;<br/>
char buffer[101];<br/>
<br/>
<br/>
HRESULT hr = CoInitialize(NULL);<br/>
if (hr != S_OK) { return 0; }<br/>
<br/>
<span class="x_Apple-tab-span" style="white-spacere //get GUID from local PC <br/>
<span class="x_Apple-tab-span" style="white-spacere hr=ADsGetObject(L"WinNT://mydomain/me", IID_IADs, (void**) &pADs); <br/>
if (hr != S_OK) <br/>
<span class="x_Apple-tab-span" style="white-spacere { <br/>
<span class="x_Apple-tab-span" style="white-spacere printf("failed to getn");<br/>
<span class="x_Apple-tab-span" style="white-spacere return 0; <br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
<br/>
if( S_OK == pADs->get_ADsPath(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("Object first AD Path: %Sn",bstr);<span class="x_Apple-tab-span" style="white-spacere
<br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
if( S_OK == pADs->get_GUID(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("Object GUID: %Sn",bstr);<span class="x_Apple-tab-span" style="white-spacere
<br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
<br/>
<span class="x_Apple-tab-span" style="white-spacere //MUST FIND A BETTER WAY <br/>
<span class="x_Apple-tab-span" style="white-spacere char pszFilter[100] = "LDAP://mydomain/";<br/>
sprintf(buffer,"%S",bstr);<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("buffer %sn",buffer);<br/>
<span class="x_Apple-tab-span" style="white-spacere unsigned int i = 0;<br/>
for(i = 0; i < strlen(buffer); ++i){<br/>
<span class="x_Apple-tab-span" style="white-spacere if (buffer == {){ buffer = <; }<br/>
<span class="x_Apple-tab-span" style="white-spacere if (buffer == }){ buffer = >; }<br/>
}<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("buffer %sn",buffer);<br/>
<span class="x_Apple-tab-span" style="white-spacere strcat(pszFilter, buffer);<span class="x_Apple-tab-span" style="white-spacere
<br/>
<br/>
<span class="x_Apple-tab-span" style="white-spacere //get infor from LDAP<br/>
//hr = ADsGetObject((LPWSTR) pszFilter, IID_IADs, (void**)&pADsGUID);<br/>
<span class="x_Apple-tab-span" style="white-spacere hr = ADsGetObject(L"LDAP://myDomain/<GUID=D83F1060-1E71-11CF-B1F3-02608C9E7553>", IID_IADs, (void**)&pADsGUID);<br/>
<span class="x_Apple-tab-span" style="white-spacere <br/>
<span class="x_Apple-tab-span" style="white-spacere if (hr !=S_OK) {printf("can not connect to LDPAn");return 0;}<span class="x_Apple-tab-span" style="white-spacere
<br/>
<br/>
<br/>
<span class="x_Apple-tab-span" style="white-spacere if( S_OK == pADsGUID->get_Name(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("Object Name: %Sn",bstr);<span class="x_Apple-tab-span" style="white-spacere
<br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
if( S_OK == pADsGUID->get_ADsPath(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("AD path: %Sn",bstr);<span class="x_Apple-tab-span" style="white-spacere
<br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
<br/>
<br/>
<span class="x_Apple-tab-span" style="white-spacere if (pADs)<br/>
<span class="x_Apple-tab-span" style="white-spacere {<br/>
<span class="x_Apple-tab-span" style="white-spacere pADs->Release();<br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
<br/>
<br/>
CoUninitialize();<br/>
<br/>
<br/>
<br/>
<br/>
I first get my GUID with
<pre class="prettyprint hr=ADsGetObject(L"WinNT://mydomain/me", IID_IADs, (void**) &pADs); [/code]
and afterwards send the GUID to the LDPA server to get the users info.
This , however, does not work and I can not connect to the LDPA server with the GUID. So my questions are
1- Am I doing something wrong?
2- How should I use the GUID to get users info, need the user group.
3- and can anyone show me a better way to add the GUID to the LDPA string, this is how Im doing it now
<pre class="prettyprint //MUST FIND A BETTER WAY
char pszFilter[100] = "LDAP://mydomain/";
sprintf(buffer,"%S",bstr);
printf("buffer %sn",buffer);
unsigned int i = 0;
for(i = 0; i < strlen(buffer); ++i){
if (buffer == {){ buffer = <; }
if (buffer == }){ buffer = >; }
}[/code]
Thanks,
Ehsan
<br/>
<br/>
View the full article
<br/>
<br/>
IADs *pADsGUID,*pADs;<br/>
BSTR bstr;<br/>
char buffer[101];<br/>
<br/>
<br/>
HRESULT hr = CoInitialize(NULL);<br/>
if (hr != S_OK) { return 0; }<br/>
<br/>
<span class="x_Apple-tab-span" style="white-spacere //get GUID from local PC <br/>
<span class="x_Apple-tab-span" style="white-spacere hr=ADsGetObject(L"WinNT://mydomain/me", IID_IADs, (void**) &pADs); <br/>
if (hr != S_OK) <br/>
<span class="x_Apple-tab-span" style="white-spacere { <br/>
<span class="x_Apple-tab-span" style="white-spacere printf("failed to getn");<br/>
<span class="x_Apple-tab-span" style="white-spacere return 0; <br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
<br/>
if( S_OK == pADs->get_ADsPath(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("Object first AD Path: %Sn",bstr);<span class="x_Apple-tab-span" style="white-spacere
<br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
if( S_OK == pADs->get_GUID(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("Object GUID: %Sn",bstr);<span class="x_Apple-tab-span" style="white-spacere
<br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
<br/>
<span class="x_Apple-tab-span" style="white-spacere //MUST FIND A BETTER WAY <br/>
<span class="x_Apple-tab-span" style="white-spacere char pszFilter[100] = "LDAP://mydomain/";<br/>
sprintf(buffer,"%S",bstr);<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("buffer %sn",buffer);<br/>
<span class="x_Apple-tab-span" style="white-spacere unsigned int i = 0;<br/>
for(i = 0; i < strlen(buffer); ++i){<br/>
<span class="x_Apple-tab-span" style="white-spacere if (buffer == {){ buffer = <; }<br/>
<span class="x_Apple-tab-span" style="white-spacere if (buffer == }){ buffer = >; }<br/>
}<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("buffer %sn",buffer);<br/>
<span class="x_Apple-tab-span" style="white-spacere strcat(pszFilter, buffer);<span class="x_Apple-tab-span" style="white-spacere
<br/>
<br/>
<span class="x_Apple-tab-span" style="white-spacere //get infor from LDAP<br/>
//hr = ADsGetObject((LPWSTR) pszFilter, IID_IADs, (void**)&pADsGUID);<br/>
<span class="x_Apple-tab-span" style="white-spacere hr = ADsGetObject(L"LDAP://myDomain/<GUID=D83F1060-1E71-11CF-B1F3-02608C9E7553>", IID_IADs, (void**)&pADsGUID);<br/>
<span class="x_Apple-tab-span" style="white-spacere <br/>
<span class="x_Apple-tab-span" style="white-spacere if (hr !=S_OK) {printf("can not connect to LDPAn");return 0;}<span class="x_Apple-tab-span" style="white-spacere
<br/>
<br/>
<br/>
<span class="x_Apple-tab-span" style="white-spacere if( S_OK == pADsGUID->get_Name(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("Object Name: %Sn",bstr);<span class="x_Apple-tab-span" style="white-spacere
<br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
if( S_OK == pADsGUID->get_ADsPath(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-spacere printf("AD path: %Sn",bstr);<span class="x_Apple-tab-span" style="white-spacere
<br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
<br/>
<br/>
<span class="x_Apple-tab-span" style="white-spacere if (pADs)<br/>
<span class="x_Apple-tab-span" style="white-spacere {<br/>
<span class="x_Apple-tab-span" style="white-spacere pADs->Release();<br/>
<span class="x_Apple-tab-span" style="white-spacere }<br/>
<br/>
<br/>
CoUninitialize();<br/>
<br/>
<br/>
<br/>
<br/>
I first get my GUID with
<pre class="prettyprint hr=ADsGetObject(L"WinNT://mydomain/me", IID_IADs, (void**) &pADs); [/code]
and afterwards send the GUID to the LDPA server to get the users info.
This , however, does not work and I can not connect to the LDPA server with the GUID. So my questions are
1- Am I doing something wrong?
2- How should I use the GUID to get users info, need the user group.
3- and can anyone show me a better way to add the GUID to the LDPA string, this is how Im doing it now
<pre class="prettyprint //MUST FIND A BETTER WAY
char pszFilter[100] = "LDAP://mydomain/";
sprintf(buffer,"%S",bstr);
printf("buffer %sn",buffer);
unsigned int i = 0;
for(i = 0; i < strlen(buffer); ++i){
if (buffer == {){ buffer = <; }
if (buffer == }){ buffer = >; }
}[/code]
Thanks,
Ehsan
<br/>
<br/>
View the full article