我正在處理活動目錄并正在閱讀此https://learn.microsoft.com/en-us/windows/win32/adsi/setting-up-c---for-adsi-development并使用上述代碼連接到它,但它沒有連接到服務器,并說行程退出,狀態碼為零
我使用了下面的代碼。
#include "stdafx.h"
#include "activeds.h"
int main(int argc, char* argv[])
{
HRESULT hr;
IADsContainer *pCont;
IDispatch *pDisp=NULL;
IADs *pUser;
// Initialize COM before calling any ADSI functions or interfaces.
CoInitialize(NULL);
hr = ADsGetObject( L"LDAP://CN=users,DC=fabrikam,DC=com",
IID_IADsContainer,
(void**) &pCont );
if ( !SUCCEEDED(hr) )
{
return 0;
}
}
我做錯了什么我完全按照檔案中所說的那樣做
uj5u.com熱心網友回復:
ADsGetObject 用于未經身份驗證的連接,即應在服務器內部執行的代碼。如果您嘗試連接到托管在單獨機器上的服務器,您應該使用 ADsOpenObject,您可能在以下鏈接 https://learn.microsoft.com/en-us/windows/win32/api/adshlp/nf中有參考-adshlp-adsopenobject ADsOpenObject 使用顯式用戶名和密碼系結,您可以嘗試以下操作
int login(LPCWSTR uname, LPCWSTR pass)
{
HRESULT hr;
IADsContainer* pCont;
IDispatch* pDisp = NULL;
IADs* pUser;
// Initialize COM before calling any ADSI functions or interfaces.
CoInitialize(NULL);
hr = ADsOpenObject(L"LDAP://machinename.domaincontroller.domain/CN=Users,DC=domaincontrollername,DC=domainname", uname, pass,
ADS_SECURE_AUTHENTICATION, // For secure authentication
IID_IADsContainer,
(void**)&pCont);
std::cout << hr << std::endl;
std::string message = std::system_category().message(hr);
std::cout << message << std::endl;
if (!SUCCEEDED(hr)) {
return 0;
}
else {
return 1;
}
}
而不是變數,您可以輸入您的用戶名和密碼,例如 L"usernameexample"
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/523351.html
標籤:C 活动目录
