Düzenle

Aracılığıyla paylaş


Creating and Deleting Objects

With ADSI, objects are created and deleted using either the IADsContainer or IDirectoryObject interface.

Creating an Object with IADsContainer

To create an object with the IADsContainer interface

  1. Bind to the container that will contain the object to be created and obtain the IADsContainer interface.
  2. Use the IADsContainer.Create method to create a new object in the container.
  3. Set the values for all of the required attributes for the object using the IADs.Put or IADs.PutEx method. The attributes required to create an object will depend on the directory service and the type of object created. For more information about creating Active Directory objects, see Creating and Deleting Active Directory Objects.
  4. Set the values for all of the desired optional attributes for the object using the IADs.Put or IADs.PutEx method.
  5. Call the IADs.SetInfo method to commit the object and its attributes. The new object is not actually created in the underlying directory service until the IADs.SetInfo method is called to commit the attributes.

Creating an Object with IDirectoryObject

To create an object with the IDirectoryObject interface

  1. Bind to the container that will contain the object to be created and obtain the IDirectoryObject interface.
  2. Allocate an array of ADS_ATTR_INFO structures that contains one structure for each attribute to be set when the object is created.
  3. Fill in an ADS_ATTR_INFO structure for each required attribute for the object. The attributes required to create an object will depend on the directory service and the type of object created. For more information about creating Active Directory objects, see Creating and Deleting Active Directory Objects.
  4. Fill in an ADS_ATTR_INFO structure for each optional attribute for the object.
  5. Use the IDirectoryObject::CreateDSObject method to create the object in the container. This method also commits the object to the underlying directory service. If the ADS_ATTR_INFO array does not contain all of the required attributes for the object, IDirectoryObject::CreateDSObject will fail.

Deleting an Object

To delete an object use the IADsContainer::Delete or the IDirectoryObject::DeleteDSObject method. These methods will fail if the deleted object contains any child objects. Use the IADsDeleteOps::DeleteObject method to delete a container and all of the container's child objects.

What happens to a deleted object depends on the underlying directory service. For more information about deleting Active Directory objects, see Creating and Deleting Active Directory Objects.