Adding attributes

Adding attributes

Post by Bob » Thu, 03 Jul 2003 15:03:09



Gidday,

Can anyone provide sample code to add an attribute to a
user object... all the examples I have seen using
DirectoryServices are for adding a user account.... and
the info is so vague I can't translate it to just adding
an attribute to an existing object...

I have also tried MSDN but it really is a waste of time
these days... info and samples provided are always either
really vague or really abstract...

I did read the reply to the post titled "Extending schema
with .Net DirectoryServices" but again it points to a
sample that adds a user object...

Anyone got any clear samples...?

Cheers

 
 
 

Adding attributes

Post by Bob » Thu, 03 Jul 2003 15:41:24


Not sure if I have my terminology correct so I'll clarify:

I want to add a STRING property/attribute to each User
object called PhotoPath (or whatever)....

Are attributes and properties the same?

Cheers

Quote:>-----Original Message-----
>Gidday,

>Can anyone provide sample code to add an attribute to a
>user object... all the examples I have seen using
>DirectoryServices are for adding a user account.... and
>the info is so vague I can't translate it to just adding
>an attribute to an existing object...

>I have also tried MSDN but it really is a waste of time
>these days... info and samples provided are always either
>really vague or really abstract...

>I did read the reply to the post titled "Extending schema
>with .Net DirectoryServices" but again it points to a
>sample that adds a user object...

>Anyone got any clear samples...?

>Cheers
>.


 
 
 

Adding attributes

Post by Nils Kaczensk » Thu, 03 Jul 2003 18:29:52


Attributes and properties are just different words for the same thing
here.

What you are planning to do is extend the AD schema. There are some
fine articles on how to do that in MSDN. Extending the schema is much
greater a task than just adding simple objects.

Look here (fix line breaks!):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnw2km
ag01/html/ExtendingtheADSchema.asp

http://msdn.microsoft.com/library/en-us/dnactdir/html/adschemaext.asp

http://msdn.microsoft.com/library/en-us/adschema/adschema/active_direct
ory_schema.asp

Nils
--
www.wurstkette.de - www.kaczenski.de - www.sqltraining.de

 
 
 

Adding attributes

Post by MVP - ADS » Fri, 04 Jul 2003 03:11:55


Did you see the post I made a few days ago about extending the schema using
System.DirectoryServices?  The thread I posted from Google shows essentially
how to do this if you read through the whole thing:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=u...

Note that it is a good idea to understand what you are doing with extending
the schema before you actually try to do this.  The Active Directory
reference should be required reading:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netd...

You can also do schema extensions with tools like LDIFDE or the UI snap-in.
Doing this programmatically probably isn't worth the effort for simply
adding a single new attribute to the schema one time.

HTH,

Joe K.


Quote:> Not sure if I have my terminology correct so I'll clarify:

> I want to add a STRING property/attribute to each User
> object called PhotoPath (or whatever)....

> Are attributes and properties the same?

> Cheers

> >-----Original Message-----
> >Gidday,

> >Can anyone provide sample code to add an attribute to a
> >user object... all the examples I have seen using
> >DirectoryServices are for adding a user account.... and
> >the info is so vague I can't translate it to just adding
> >an attribute to an existing object...

> >I have also tried MSDN but it really is a waste of time
> >these days... info and samples provided are always either
> >really vague or really abstract...

> >I did read the reply to the post titled "Extending schema
> >with .Net DirectoryServices" but again it points to a
> >sample that adds a user object...

> >Anyone got any clear samples...?

> >Cheers
> >.

 
 
 

Adding attributes

Post by Bob » Fri, 04 Jul 2003 07:39:00


Hi Joe,

Yes I did see your post and I did check out the sample...
I try not to post a question until I've done at least some
research...

I didn't really find it that useful as once again it shows
the creation of a user object, not just an attribute
belonging to a user object... from the sample code I am
unsure how to achieve my simple goal (which will extend to
something more complex once completed)...

Also, that sample is really really vague about what all
the properties being set are for, whether they are
required, and how you look these things up (to know you
have to use them)....

Anyway, appreciate your reply, and I agree that if only
adding 1 attribute then the GUI is probably the easiest
(and no doubt safest) approach. The project I am scoping
out requires adding more than just 1 attribute for a large
govt dept and as the changes may be deployed to more than
1 site (not linked) I'd rather do it in code for
consistency (and for the knowledge)...

Cheers

Quote:>-----Original Message-----
>Did you see the post I made a few days ago about

extending the schema using
Quote:>System.DirectoryServices?  The thread I posted from

Google shows essentially
Quote:>how to do this if you read through the whole thing:

>http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-

8&threadm=u88%24TTlzCHA.1672%40TK2MSFTNGP09&rnum=1
Quote:

>Note that it is a good idea to understand what you are

doing with extending
Quote:>the schema before you actually try to do this.  The
Active Directory
>reference should be required reading:

>http://msdn.microsoft.com/library/default.asp?

url=/library/en-us/netdir/ad/extending_the_schema.asp?
frame=true

>You can also do schema extensions with tools like LDIFDE
or the UI snap-in.
>Doing this programmatically probably isn't worth the
effort for simply
>adding a single new attribute to the schema one time.

>HTH,

>Joe K.



>> Not sure if I have my terminology correct so I'll
clarify:

>> I want to add a STRING property/attribute to each User
>> object called PhotoPath (or whatever)....

>> Are attributes and properties the same?

>> Cheers

>> >-----Original Message-----
>> >Gidday,

>> >Can anyone provide sample code to add an attribute to a
>> >user object... all the examples I have seen using
>> >DirectoryServices are for adding a user account.... and
>> >the info is so vague I can't translate it to just
adding
>> >an attribute to an existing object...

>> >I have also tried MSDN but it really is a waste of time
>> >these days... info and samples provided are always
either
>> >really vague or really abstract...

>> >I did read the reply to the post titled "Extending
schema
>> >with .Net DirectoryServices" but again it points to a
>> >sample that adds a user object...

>> >Anyone got any clear samples...?

>> >Cheers
>> >.

>.

 
 
 

Adding attributes

Post by MVP - ADS » Fri, 04 Jul 2003 12:46:35


I'm not sure I follow what was wrong with the code from the thread in Google
or what I pointed out that showed how to add a user, but in any case I took
the code, added the fixes discovered later in the thread, added a few more
attributes and turned it into a VB.NET function you can call.  I haven't had
time to test this yet, so this may not be perfect.  Let me know if you find
a problem with it or make some improvements:

        Private Function AddAttributeToSchema( _
            ByVal commonName As String, _
            ByVal ldapDisplayName As String, _
            ByVal isSingleValued As Boolean, _
            ByVal instanceType As Integer, _
            ByVal oMSyntax As Integer, _
            ByVal attributeSyntax As String, _
            ByVal searchFlags As Integer, _
            ByVal isMemberOfPartialAttributeSet As Boolean, _
            ByVal attributeOID As String, _
            ByVal schemaIdGuid As Guid, _
            ByVal rangeLower As Integer, _
            ByVal rangeUpper As Integer, _
            ByVal linkId As Integer, _
            ByVal description As String _
            ) As DirectoryEntry

            'Originally inspired by code posted by Jamie Vachon on
microsoft.public.adsi.general

            'might consider passing in the schemaRoot so that the caller can
control how the binding
            'occurs (credentials, server name, etc.).  This is ok for demo
purposes.
            Dim rootDSE As New DirectoryEntry("LDAP://rootDSE")
            Dim schemaRoot As New DirectoryEntry("LDAP://" &
DirectCast(rootDSE.Properties("schemaNamingContext").Value, System.String))

            Dim schemaAttribute As New DirectoryEntry()

            schemaAttribute = schemaRoot.Children.Add("cn=" & commonName,
"attributeSchema")
            schemaAttribute.Properties("lDAPDisplayName").Value =
ldapDisplayName
            schemaAttribute.Properties("isSingleValued").Value =
isSingleValued
            schemaAttribute.Properties("instanceType").Value = instanceType
            schemaAttribute.Properties("oMSyntax").Value = oMSyntax
            schemaAttribute.Properties("attributeSyntax").Value =
attributeSyntax
            schemaAttribute.Properties("searchFlags").Value = searchFlags

schemaAttribute.Properties("isMemberOfPartialAttributeSet").Value =
isMemberOfPartialAttributeSet
            schemaAttribute.Properties("attributeID").Value = attributeOID
            'could allow this to be assigned randomly with Guid.NewGuid() as
well, but this allows
            'the caller to specify
            schemaAttribute.Properties("schemaIDGUID").Value =
schemaIdGuid.ToByteArray()

            schemaAttribute.Properties("description").Value = description

            'might want to change the following three values so that they
are not set on the
            'object if they are set to an invalid value.  Perhaps an
overloaded method
            'or a special "ignore" value would be the way to go...
            schemaAttribute.Properties("rangeLower").Value = rangeLower
            schemaAttribute.Properties("rangeUpper").Value = rangeUpper
            schemaAttribute.Properties("linkID").Value = linkId
            schemaAttribute.CommitChanges()

            Return schemaAttribute

        End Function

Given that, you still need to know what values to pass in for the function
arguments.  This is very well explained in the SDK documentation:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netd...

You should also definitely read this too:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netd...

Hopefully that will give you everything you need to successfully add
attributes to the schema programmatically using VB.NET.  You will still need
to associate those attributes with classSchema objects in order to use them,
but that is pretty easy to do by updating the mayContain attribute value of
the appropriate classSchema object.

Joe K.


Quote:> Hi Joe,

> Yes I did see your post and I did check out the sample...
> I try not to post a question until I've done at least some
> research...

> I didn't really find it that useful as once again it shows
> the creation of a user object, not just an attribute
> belonging to a user object... from the sample code I am
> unsure how to achieve my simple goal (which will extend to
> something more complex once completed)...

> Also, that sample is really really vague about what all
> the properties being set are for, whether they are
> required, and how you look these things up (to know you
> have to use them)....

> Anyway, appreciate your reply, and I agree that if only
> adding 1 attribute then the GUI is probably the easiest
> (and no doubt safest) approach. The project I am scoping
> out requires adding more than just 1 attribute for a large
> govt dept and as the changes may be deployed to more than
> 1 site (not linked) I'd rather do it in code for
> consistency (and for the knowledge)...

> Cheers

> >-----Original Message-----
> >Did you see the post I made a few days ago about
> extending the schema using
> >System.DirectoryServices?  The thread I posted from
> Google shows essentially
> >how to do this if you read through the whole thing:

> >http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-
> 8&threadm=u88%24TTlzCHA.1672%40TK2MSFTNGP09&rnum=1

> >Note that it is a good idea to understand what you are
> doing with extending
> >the schema before you actually try to do this.  The
> Active Directory
> >reference should be required reading:

> >http://msdn.microsoft.com/library/default.asp?
> url=/library/en-us/netdir/ad/extending_the_schema.asp?
> frame=true

> >You can also do schema extensions with tools like LDIFDE
> or the UI snap-in.
> >Doing this programmatically probably isn't worth the
> effort for simply
> >adding a single new attribute to the schema one time.

> >HTH,

> >Joe K.

 
 
 

Adding attributes

Post by Bob » Fri, 04 Jul 2003 20:02:03


Ok... so the code sample was to create a new attribute and nothing to do
with adding a user... I'm sure I saw something which implied it was...
that's why I couldn't figure out what all the extra properties were for...

Anyway, I'm a bit more with it now so I'll have a play and see what I can
break, I mean create... and the links you provided were good also... I've
searched MSDN many time in relation to this but didn't come across at least
the first link you supplied...

Anyway, I'll see how I go from here, cheers!



Quote:> I'm not sure I follow what was wrong with the code from the thread in
Google
> or what I pointed out that showed how to add a user, but in any case I
took
> the code, added the fixes discovered later in the thread, added a few more
> attributes and turned it into a VB.NET function you can call.  I haven't
had
> time to test this yet, so this may not be perfect.  Let me know if you
find
> a problem with it or make some improvements:

>         Private Function AddAttributeToSchema( _
>             ByVal commonName As String, _
>             ByVal ldapDisplayName As String, _
>             ByVal isSingleValued As Boolean, _
>             ByVal instanceType As Integer, _
>             ByVal oMSyntax As Integer, _
>             ByVal attributeSyntax As String, _
>             ByVal searchFlags As Integer, _
>             ByVal isMemberOfPartialAttributeSet As Boolean, _
>             ByVal attributeOID As String, _
>             ByVal schemaIdGuid As Guid, _
>             ByVal rangeLower As Integer, _
>             ByVal rangeUpper As Integer, _
>             ByVal linkId As Integer, _
>             ByVal description As String _
>             ) As DirectoryEntry

>             'Originally inspired by code posted by Jamie Vachon on
> microsoft.public.adsi.general

>             'might consider passing in the schemaRoot so that the caller
can
> control how the binding
>             'occurs (credentials, server name, etc.).  This is ok for demo
> purposes.
>             Dim rootDSE As New DirectoryEntry("LDAP://rootDSE")
>             Dim schemaRoot As New DirectoryEntry("LDAP://" &
> DirectCast(rootDSE.Properties("schemaNamingContext").Value,
System.String))

>             Dim schemaAttribute As New DirectoryEntry()

>             schemaAttribute = schemaRoot.Children.Add("cn=" & commonName,
> "attributeSchema")
>             schemaAttribute.Properties("lDAPDisplayName").Value =
> ldapDisplayName
>             schemaAttribute.Properties("isSingleValued").Value =
> isSingleValued
>             schemaAttribute.Properties("instanceType").Value =
instanceType
>             schemaAttribute.Properties("oMSyntax").Value = oMSyntax
>             schemaAttribute.Properties("attributeSyntax").Value =
> attributeSyntax
>             schemaAttribute.Properties("searchFlags").Value = searchFlags

> schemaAttribute.Properties("isMemberOfPartialAttributeSet").Value =
> isMemberOfPartialAttributeSet
>             schemaAttribute.Properties("attributeID").Value = attributeOID
>             'could allow this to be assigned randomly with Guid.NewGuid()
as
> well, but this allows
>             'the caller to specify
>             schemaAttribute.Properties("schemaIDGUID").Value =
> schemaIdGuid.ToByteArray()

>             schemaAttribute.Properties("description").Value = description

>             'might want to change the following three values so that they
> are not set on the
>             'object if they are set to an invalid value.  Perhaps an
> overloaded method
>             'or a special "ignore" value would be the way to go...
>             schemaAttribute.Properties("rangeLower").Value = rangeLower
>             schemaAttribute.Properties("rangeUpper").Value = rangeUpper
>             schemaAttribute.Properties("linkID").Value = linkId
>             schemaAttribute.CommitChanges()

>             Return schemaAttribute

>         End Function

> Given that, you still need to know what values to pass in for the function
> arguments.  This is very well explained in the SDK documentation:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netd...
Quote:

> You should also definitely read this too:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netd...

- Show quoted text -

> Hopefully that will give you everything you need to successfully add
> attributes to the schema programmatically using VB.NET.  You will still
need
> to associate those attributes with classSchema objects in order to use
them,
> but that is pretty easy to do by updating the mayContain attribute value
of
> the appropriate classSchema object.

> Joe K.



> > Hi Joe,

> > Yes I did see your post and I did check out the sample...
> > I try not to post a question until I've done at least some
> > research...

> > I didn't really find it that useful as once again it shows
> > the creation of a user object, not just an attribute
> > belonging to a user object... from the sample code I am
> > unsure how to achieve my simple goal (which will extend to
> > something more complex once completed)...

> > Also, that sample is really really vague about what all
> > the properties being set are for, whether they are
> > required, and how you look these things up (to know you
> > have to use them)....

> > Anyway, appreciate your reply, and I agree that if only
> > adding 1 attribute then the GUI is probably the easiest
> > (and no doubt safest) approach. The project I am scoping
> > out requires adding more than just 1 attribute for a large
> > govt dept and as the changes may be deployed to more than
> > 1 site (not linked) I'd rather do it in code for
> > consistency (and for the knowledge)...

> > Cheers

> > >-----Original Message-----
> > >Did you see the post I made a few days ago about
> > extending the schema using
> > >System.DirectoryServices?  The thread I posted from
> > Google shows essentially
> > >how to do this if you read through the whole thing:

> > >http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-
> > 8&threadm=u88%24TTlzCHA.1672%40TK2MSFTNGP09&rnum=1

> > >Note that it is a good idea to understand what you are
> > doing with extending
> > >the schema before you actually try to do this.  The
> > Active Directory
> > >reference should be required reading:

> > >http://msdn.microsoft.com/library/default.asp?
> > url=/library/en-us/netdir/ad/extending_the_schema.asp?
> > frame=true

> > >You can also do schema extensions with tools like LDIFDE
> > or the UI snap-in.
> > >Doing this programmatically probably isn't worth the
> > effort for simply
> > >adding a single new attribute to the schema one time.

> > >HTH,

> > >Joe K.

 
 
 

1. error querying a newly added attribute

Hi,

I extended the schema with newly added attributes and upon querying
them I get the following error:

Error Type:
Provider (0x80004005)
Unspecified error
/ADSQuery.asp, line 52

I am using integrated windows authentication.

Another peculiar thing I noticed was that I was unable to query some
of the existing attributes of the user class as well if I didn't put
the ADsPath as follows:

"LDAP://" + objRootDSE.Get("dnsHostName") + "/"  +
objRootDSE.Get("defaultNamingContext")

i.e. if I do not give objRootDSE.Get("dnsHostName") in the LDAP path I
get the same unspecified error while querying certain fields such as
flags.
And now I am unable to query the attibutes I created.

Any help is geratly appreciated.

Thanks
Eqbal

2. IDE controller question

3. Adding Attributes to the Search Index

4. could not install cluster service ??

5. Adding attributes to LDAP classes

6. list box / redirect

7. Adding attributes to classes

8. Adding attributes to the root node

9. Add new attributes to existing Hardware Inventory objects

10. How to use the classes and attributes that i have added?

11. Adding an Attribute to the AD

12. Adding custom attributes to AD