Click to See Complete Forum and Search --> : extend the AD schema


igor.pankov
March 31st, 2004, 02:30 AM
I want to extend the schema to add a new attribute to a User
I use next code

Dim objRoot
Dim objSchema
Dim newattr
Dim objUserClass

objRoot = GetObject("LDAP://RootDSE")
objSchema = GetObject("LDAP://" & objRoot.Get("schemaNamingContext"))

newattr = objSchema.Create("attributeSchema", "cn=ual_8")

newattr.Put("isSingleValued", True)
newattr.Put("oMSyntax", 2)
newattr.Put("attributeSyntax", "2.5.5.9")
newattr.Put("rangeLower", 0)
newattr.Put("rangeUpper", 6)
newattr.Put("searchFlags", 1)
newattr.Put("attributeId", cAttributeOID)
newattr.SetInfo()

objUserClass = objSchema.GetObject("classSchema", "cn=user")
Dim attribOid() As String = {cAttributeOID}
objUserClass.PutEx(3, "mayContain", attribOid)
objUserClass.SetInfo()

objRoot.Put("schemaUpdateNow", 1)
objRoot.SetInfo()


on the string
objUserClass.PutEx(3, "mayContain", attribOid)
I receive exception

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in microsoft.visualbasic.dll
Additional information: Unspecified error

Craig Gemmill
March 31st, 2004, 04:47 PM
A few things to check:

1) Try using an Object array instead:

Dim attribOid() As Object = {cAttributeOID}

2) I can't see where cAttributeOID is delcared at, or populated... are you sure it has valid contents?

= {cAttributeOID}

3) Are you sure your program has the security to access that entry?

EDIT: Forgot to mention that if you keep digging into the exception, you might find a better reason then "Unspecified error".

ie: exception.innerexception.innerexception.message