I have a problem getting an IADsContainer object from ADsOpenObject() by using the WinNT provider from a service on a remote machine.
I've been able to get the code working in the following scenarios except number 4
#include <iostream>
#include <Adshlp.h>
#include <comdef.h>
IADsContainer* container = nullptr;
HRESULT hres = ADsOpenObject( L"WinNT://192.168.1.30", L"Administrator", L"someAdminPass", ADS_SECURE_AUTHENTICATION | ADS_READONLY_SERVER, IID_IADsContainer, (void**)&container );
if( SUCCEEDED(hres) )
{
// do stuff with the container object
}
else
{
_com_error err( hres );
LPCTSTR errMsg = err.ErrorMessage();
std::wcout << errMsg;
}
I expect hres to be S_OK and valid 'container' pointer but I only get E_FAIL with error string "Unspecified error"
The issue is resolved thanks to the guides in the comments from @DrakeWu-MSFT!
I just needed to specify a FQDN username. If your machine domain is "DOMAIN.COM' then the username string should be "[email protected]". This solved the issue for me. Also big "thanks" to MS for such a descriptive error message... :)
The main code line now looks like this:
HRESULT hres = ADsOpenObject( L"WinNT://192.168.1.30", L"[email protected]", L"someAdminPass", ADS_SECURE_AUTHENTICATION | ADS_READONLY_SERVER, IID_IADsContainer, (void**)&container );
P.S. Beware that there are other WinAPI functions that don't like FQDN username.