سؤال

This is my program. I am not able to bind. I dont know what is the problem. I think there is a problem with connection string. How to find the LDAP connection string?

    #include <iostream>
    #include <conio.h>
    #include <wchar.h>
    #include <objbase.h>
    #include <activeds.h>
    #include <AdsHlp.h>

    using namespace std;
    const IID IID_IADs = {0xFD8256D0, 0xFD15, 0x11CE, {0xAB,0xC4,0x02,0x60,0x8C,0x9E,0x75,0x53}};
    int main(int argc, CHAR* argv[])
    {
    IADs *pObject;
    HRESULT hr;
    ::CoInitialize(NULL);
            hr = ADsOpenObject(L"ldap://server1",L"cn=Manager,dc=maxcrc,dc=com",L"secret",
                ADS_SECURE_AUTHENTICATION, 
                IID_IADs,
                (void**)&pObject);

    if(SUCCEEDED(hr))
    {
    cout<<"Success";
    pObject->Release();
    }
    else
    cout<<"Unsuccessful";

    CoUninitialize();
    getch();
    return 0;
    }
هل كانت مفيدة؟

المحلول

I'm not sure if the connection string in C will be like in C++, but for C++ we have to set username and password in the connection string like this:

hr = ADsOpenObject(L"LDAP://CN=Manager,DC=maxcrc,DC=com",
                   "username",
                   "password",
                   ADS_SECURE_AUTHENTICATION, 
                   IID_IADs,
                   (void**) &pObject);

نصائح أخرى

I never use ADSI COM object from 'C', but when I use it from PowerShell I met an error if I don't use capital letters for 'LDAP' in the connexion URL (PowerShell is not case sensitive). Have a look to LDAP ADsPath all the URLs begin by 'LDAP' in capital letters.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top