Skip to content

Instantly share code, notes, and snippets.

@marylly
Created May 9, 2024 17:34
Show Gist options
  • Save marylly/d7ec736c9ca7b8fc7332c620c8ff85c8 to your computer and use it in GitHub Desktop.
Save marylly/d7ec736c9ca7b8fc7332c620c8ff85c8 to your computer and use it in GitHub Desktop.
// CPPSandbox.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <activeds.h>
#include <AdsHlp.h>
int main()
{
HRESULT hr;
hr = CoInitialize(NULL);
IADsADSystemInfo* pSys;
hr = CoCreateInstance(CLSID_ADSystemInfo,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsADSystemInfo,
(void**)&pSys);
BSTR siteName;
BSTR dnsServer;
hr = pSys->GetAnyDCName(&dnsServer);
printf("Domain controller site: %S\n", dnsServer);
hr = pSys->GetDCSiteName(dnsServer, &siteName);
printf("Domain controller site: %S\n", siteName);
IADsContainer* pUser;
// Funciona -> hr = ADsGetObject(L"LDAP://MC-MIA-DC-00.magaya.com/cn=users,dc=magaya,dc=com", IID_IADs, (VOID**)&pUser);
// Funciona -> hr = ADsGetObject(L"LDAP://magaya.com/cn=users,dc=magaya,dc=com", IID_IADs, (VOID**)&pUser);
hr = ADsGetObject(L"LDAP://magaya.com/cn=users,dc=magaya,dc=com", IID_IADsContainer, (VOID**)&pUser);
BSTR bstr;
LPWSTR attr[] = { (LPWSTR)"LDAPDisplayName" };
ADS_SEARCH_HANDLE hSearchResult;
IDirectorySearch *pSearch = NULL;
DWORD dwCount = sizeof(attr) / sizeof(LPWSTR);
HRESULT hrSearch = pSearch->ExecuteSearch((LPWSTR)"(objectClass=group)", attr, dwCount, &hSearchResult);
pSearch->CloseSearchHandle(hSearchResult);
CoUninitialize();
/*BSTR bstr;
HRESULT userName = pUser->get_Name(&bstr);
std::cout << "My user name :\n" << userName;*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment