Directory Services |
With the ADSI LDAP provider, you can only create a global user account. Local accounts reside in the SAM database and must be created using the WinNT provider. For more information about creating a user object with the WinNT provider, see WinNT User Object.
To create a user object
If the IDirectoryObject interface is used, the new object is created when the CreateDSObject method is called. The minimum attributes, including the objectClass, must be specified in the ADS_ATTR_INFO array passed to the CreateDSObject method.
The following code example creates a user account with the default attributes.
Dim ou As IADs Dim usr as IADsUser On Error GoTo Cleanup Set ou = GetObject("LDAP://OU=Finance,DC=Fabrikam,DC=COM") Set usr = ou.Create("user", "cn=Jeff Smith") usr.Put "samAccountName", "jeffsmith" usr.SetInfo Cleanup: If (Err.Number <> 0) Then MsgBox ("An error has occurred. " & Err.Number) End If Set ou = Nothing Set usr = Nothing
The following code example creates a user account with the default attributes. For brevity, error checking is omitted.
#include <activeds.h> int main() { HRESULT hr = CoInitialize(NULL); IADsContainer *pCont; IADsUser *pUser; LPWSTR adsPath = L"LDAP://serv1/CN=Users,dc=Fabrikam,dc=com"; LPWSTR usrPass = NULL; LPWSTR usrName = NULL; // Add code to securely get the username and password or leave // as NULL to use the current security context. hr = ADsOpenObject(adsPath, usrName, usrPass, ADS_SECURE_AUTHENTICATION, IID_IADsContainer, (void**)&pCont); IDispatch *pDisp; hr = pCont->Create(CComBSTR("user"), CComBSTR("cn=Jeff Smith"), &pDisp); pCont->Release(); hr = pDisp->QueryInterface(IID_IADsUser,(void**)&pUser); pDisp->Release(); VARIANT var; VariantInit(&var); V_BSTR(&var) = L"jeffsmith"; V_VT(&var)=VT_BSTR; hr = pUser->Put(CComBSTR("samAccountName"), var); hr = pUser->SetInfo(); VariantClear(&var); pUser->Release(); CoUninitialize(); return 0; }