Platform SDK: Active Directory, ADSI, and Directory Services |
The property methods of the IADs interface get or set the properties described in the following table. For a general discussion of property methods, see Interface Property Methods.
Property | Description |
---|---|
AdsPath
[Visual Basic] [C++] |
The ADsPath string of this object. The string uniquely identifies this object in a networked environment. The object can always be retrieved using this path. |
Class
[Visual Basic] [C++] |
The name of the Schema class of this object. |
GUID
[Visual Basic] [C++] |
The globally unique identifier of the directory object. The IADs interface converts the GUID from an octet string, as stored on a directory server, into a string format. |
Name
[Visual Basic] [C++] |
The relative name of the object as named within the underlying directory service. This name distinguishes this object from its siblings. |
Parent
[Visual Basic] [C++] |
The ADsPath string of the parent container. Active Directory™ does not permit the formation of the ADsPath of a given object by concatenating the Parent and Name properties. While this operation might work in some providers, it is not guaranteed to work for all implementations. The ADsPath is guaranteed to be valid and should always be used to retrieve an object's interface pointer. |
Schema
[Visual Basic] [C++] |
The ADsPath string of the Schema class object of this object |
In Active Directory, the GUID returned from IADs::get_GUID or obj.GUID is a string of hexadecimals. You can use the resultant GUID to bind to the object directly.
Dim x As IADs Set x = GetObject("LDAP://servername/<GUID=xxx>")
where xxx is the value returned from the obj.GUID property or the IADs::get_GUID property method. For more information, see Using objectGUID to Bind to an Object.
When an object is created using a GUID, it has a GUID representation. When created using a domain name (DN), it has a DN representation. Depending upon the object representations, ADSI returns different values for the Name, ADsPath, and Parent properties of the object. Suppose that we have a user object, identified by its UPN as "jane_doe@Fabrikam.com". The DN and GUID are, respectively, "CN=Jane Doe, CN=Users, DC=Fabrikam, DC=com" and "c0f59dfcf507d311a99e0000f879f7c7". The following table illustrates the differences in the two object representations.
DN Representation | GUID Represented | |
---|---|---|
Name | CN=Jane Doe | <GUID=c0f59dfcf507d311a99e0000f879f7c7> |
Parent | LDAP://server/CN=Users,DC=Fabrikam,DC=com | LDAP://server |
ADsPath | LDAP://server/CN=Jane Doe,CN=Users,DC=Fabrikam,DC=com | LDAP://server/<GUID=c0f59dfcf507d311a99e0000f879f7c7> |
Thus, if you have an object obtained using its GUID (or SID) and want to retrieve the Name, AdsPath, or Parent property values in its DN representation, you must rebind to the object using its distinguished name.
' Bind to an object using its GUID. Set obj1 = GetObject("LDAP://<GUID=xxxx>") ' Rebind to the object using its distinguished name Set obj2 = GetObject("LDAP://" & obj1.Get("distinguishedName")) Debug.Print obj2.Name Debug.Print obj2.ADsPath Debug.Print obj2.Parent
Suppose you have bound to an object using its GUID and would like to delete the object. One way to accomplish this is to ask the container to perform its Delete method. To do this, you need to get the object's immediate parent object. As can be seen from the comparison given above, you must rebind to the object using its distinguished name before submitting the request to the proper container. Otherwise, the container may not recognize the object in question.
Note The WinNT provider does not support binding using the object's GUID. And it returns the GUID property in a slightly different string format.
The following Visual Basic® code snippet illustrates how to retrieve object information using property methods of the IADs interface.
Dim x As IADs Dim parent As IADsContainer Dim cls As IADsClass Dim op As Variant Set x = GetObject("WinNT://Fabrikam/Administrator") Debug.Print "Object Name: " & x.Name Debug.Print "Object Path: " & x.ADsPath Debug.Print "Object Class: " & x.Class 'Get more information on object schema information Set cls = GetObject(x.Schema) Debug.Print "Class Name is: " & cls.Name For Each op In cls.OptionalProperties Debug.Print "Optional Property: & op Next op
The following VBScript/ASP code snippet illustrates how to retrieve object information using property methods of the IADs interface.
<HTML> <head><title></title></head> <body> <% Dim x Set x = GetObject("WinNT://Fabrikam/Administrator") Response.Write "Object Name: " & x.Name & "<br>" Response.Write "Object Path: " & x.ADsPath & "<br>" Response.Write "Object Class: " & x.Class & "<br>" 'Get more information on object schema information Set cls = GetObject(x.Schema) Response.Write "Class Name is: " & cls.Name & "<br>" For Each op In cls.OptionalProperties Response.Write "Optional Property: & op & "<br>" Next op %> </body> </html>
The following C++ code snippet shows how to work with the property methods of the IADs interface.
#include <stdio.h> #include <activeds.h> int main(int argc, char* argv[]) { IADs *pADs; IADsUser *pADsUser; IADsClass *pCls; BSTR bstr; HRESULT hr = CoInitialize(NULL); if (hr != S_OK) { return 0; } hr=ADsGetObject(L"WinNT://Fabrikam/Administrator", IID_IADsUser, (void**) &pADsUser); if (hr != S_OK) { return 0; } hr = pADsUser->QueryInterface(IID_IADs, (void**) &pADs); if( hr !=S_OK) { return 0;} pADsUser->Release(); if( S_OK == pADs->get_Name(&bstr) ) { printf("Object Name: %S\n",bstr); } if( S_OK == pADs->get_ADsPath(&bstr) ) { printf("Object path: %S\n",bstr); } if( S_OK == pADs->get_Class(&bstr) ) { printf("Object class: %S\n",bstr); } hr = pADs->get_Schema(&bstr); if ( hr != S_OK) {return 0;} hr = ADsGetObject(bstr,IID_IADsClass, (void**)&pCls); if ( hr != S_OK) {return 0;} if( S_OK == pCls->get_Name(&bstr) ) { printf("Class name is %S\n", bstr); } CoUninitialize(); return 1; }