Platform SDK: Active Directory, ADSI, and Directory Services |
The IDirectoryObject::CreateDSObject method creates a child of the current directory service object.
HRESULT CreateDSObject( LPWSTR pszRDNName, PADS_ATTR_INFO pAttributeEntries, DWORD dwNumAttributes, IDispatch **ppObject );
This method returns the standard return values, including S_OK for a successful operation. For other return values, see ADSI Error Codes.
You must specify all attributes that need to be initialized on creation in the pAttributeEntries array. You may also specify optional attributes.
The following is a C/C++ code snippet that illustrates how to create a user object using the IDirectoryObject::CreateDSObject method.
HRESULT hr; IDirectoryObject *pDirObject=NULL; ADSVALUE sAMValue; ADSVALUE uPNValue; ADSVALUE classValue; LPDISPATCH pDisp; ADS_ATTR_INFO attrInfo[] = { { L"objectClass", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &classValue, 1 }, {L"sAMAccountName", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &sAMValue, 1}, {L"userPrincipalName", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, &uPNValue, 1}, }; DWORD dwAttrs = sizeof(attrInfo)/sizeof(ADS_ATTR_INFO); classValue.dwType = ADSTYPE_CASE_IGNORE_STRING; classValue.CaseIgnoreString = L"user"; sAMValue.dwType=ADSTYPE_CASE_IGNORE_STRING; sAMValue.CaseIgnoreString = L"mikes"; uPNValue.dwType=ADSTYPE_CASE_IGNORE_STRING; uPNValue.CaseIgnoreString = L"mikes@Microsoft.com"; hr = ADsGetObject(L"LDAP://OU=Sales,DC=Microsoft,DC=com", IID_IDirectoryObject, (void**) &pDirObject ); if ( SUCCEEDED(hr) ) { hr = pDirObject->CreateDSObject( L"CN=Neil Smith", attrInfo, dwAttrs, &pDisp ); pDisp->Release(); } pDirObject->Release();
Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
Windows 95/98: Requires Windows 95 or later (with DSClient).
Header: Declared in Iads.h.