WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Pull all ObjectClass Items

Keywords: 	 ObjectClass

Question:

Is there a way to pull all currently-defined ObjectClasses?

I am using the dsFindPath and a few other ADSI calls to find info on certain classes, like 'group' but it would be nice if i could extract a list of all classes and display them as a choice list, then i can pick one out and get a list of those types, and then get properties for them.

Answer:

Unfortunately, there is not a simple function call to obtain a list of class names but there is a way to get the information. However, its not straight forward. The somewhat convoluted script below may help you get all class names in a directory. The idea is to traverse the directory service object hierarchy looking for new class names. Every time one is found we add it to a tab delimited list.

Caution: The script has not been thoroughly tested so you may need to tweak it a bit. It also can take quite a while to run depending on the our hardware and network connection.


; Add the extender
AddExtender(FileFullName( "wwads34I.dll")) 

dsSetCredent("rtest", "***********")

; Initialize some variables.
sAllClasses = "" ; Our results - must be initialize.
nDepth = 0 ; Always set to 0 at the start.
sPath = "LDAP://myserver" ; Our starting point in the object tree.

; This does all the work. 
gosub GetClasses

; Display the results.
message("List of classes", sAllClasses )

nCount = ItemCount(sAllClasses, @Tab)

message( "Number of classes", nCount)

exit


;********************************************************************
;* Name: GetClasses
;*
;* Purpose: Traverses an Active Directory object hierarchy. 
;* 
;********************************************************************/
:GetClasses

if strlen(sPath) == 0 then return ; This should be an error.

; Add this objects class name.
gosub AddObjectsClass

; Get child paths.
sChildPaths%nDepth% = dsGetChldPath(sPath, "")
nChildCount%nDepth% = ItemCount(sChildPaths%nDepth%, @Tab)

; Check each child.
while nChildCount%nDepth% > 0

; Get the next sibling.
sPath = ItemExtract(1,sChildPaths%nDepth%, @Tab)
sChildPaths%nDepth% = ItemRemove(1, sChildPaths%nDepth%, @Tab)

; Check the children of this sibling.
nDepth = nDepth + 1 
gosub GetClasses ; Recurse to the next level.
nDepth = nDepth - 1 

nChildCount%nDepth% = nChildCount%nDepth% - 1
endwhile

return ; GetClasses


;********************************************************************
;* Name: AddObjectsClass
;*
;* Purpose: Adds an AD object's classes to a list of class names.
;* 
;********************************************************************/
:AddObjectsClass

; Get the class names
sClassList = dsGetProperty( sPath, "objectClass")

; Objects can have more than one class.
nNameCount = Itemcount(sClassList, @TAB)
for i=1 to nNameCount

sClass = ItemExtract(i, sClassList, @Tab)

; Check if class name is already in list.
if ItemLocate (sClass, sAllClasses, @TAB) == 0

; Add to the class list. 
sAllClasses = ItemInsert(sClass, -1, sAllClasses, @TAB)
endif
next

return ; AddObjectsClass

Article ID:   W14518
Filename:   How to Pull all ObjectClass Items.txt
File Created: 2001:03:02:14:40:32
Last Updated: 2001:03:02:14:40:32