I need to use TsUserEx in C#. I found this code from here:
http://msdn.microsoft.com/library/de...dstsuserex.asp
I've never coded in C++ and I can't read it. Can anyone translate what
it's doing at each step? I know there are comments but they leave out
bits and don't make sense. For example, there are two comments which
read "Get the IADsTSUser interface from the user object." and yet they
describe different code. I think that's the key bit that I need to
understand. Can anyone explain it in more detail?
IADsContainer *pContainer = NULL;
IDispatch *pNewObject = NULL;
IADsTSUserEx *pTSUser = NULL;
IADsUser *pUser = NULL;
HRESULT hr = ERROR_SUCCESS;
CoInitialize(NULL);
//
// Bind to the known container.
//
hr = ADsGetObject(L"LDAP://CN=Users,DC=Server1,DC=Domain,DC=com",
IID_IADsContainer,
(void**)&pContainer);
if( !SUCCEEDED(hr)) {
wprintf(L"ADsGetObject ret failed with 0x%x\n", hr);
return FALSE;
}
//
// Create the new Active Directory Service Interfaces User object.
//
hr = pContainer->Create(L"user",
L"cn=test3",
&pNewObject);
pContainer->Release();
if( !SUCCEEDED(hr)) {
wprintf(L"Create ret failed with 0x%x\n", hr);
return FALSE;
}
//
// Get the IADsTSUser interface from the user object.
//
hr = pNewObject->QueryInterface(IID_IADsTSUserEx, (void**)&pTSUser);
if( !SUCCEEDED(hr)) {
wprintf(L"QueryInterface for IADsTSUser failed with ret 0x%x\n", hr);
return FALSE;
}
//
// Get the IADsTSUser interface from the user object.
//
hr = pNewObject->QueryInterface(IID_IADsUser, (void**)&pUser);
if( !SUCCEEDED(hr)) {
wprintf(L"QueryInterface for IAsUser failed with 0x%x\n", hr);
return FALSE;
}
pNewObject->Release();
//
// Set TerminalServicesProfilePath
//
pTSUser->put_TerminalServicesProfilePath(L"c:\\windows") ;
pTSUser->Release();
//
// Commit the object data to the directory.
//
pUser->SetInfo();
pUser->Release();
CoUninitialize();