vb.net - Query, edit and add attributes in objects from Active Directory -



vb.net - Query, edit and add attributes in objects from Active Directory -

i need create little app using visual basic retrieve user advertisement , edit/add attributes. code here queries ldap , fills textboxes info found in object property. vb knowledge limited please understand question, want know if there's improve ways accomplish goal:

dim desystem new directoryentry("ldap://etc") dim dssystem new directorysearcher(desystem) dim srsystem searchresult seek dssystem.filter = ("(&(objectclass=user)(samaccountname=" & textbox1.text & "))") dssystem.searchscope = searchscope.subtree dssystem.propertiestoload.add("samaccountname") dssystem.propertiestoload.add("givenname") dssystem.propertiestoload.add("sn") dssystem.propertiestoload.add("proxyaddresses") srsystem = dssystem.findone() textbox2.text = srsystem.properties("givenname").item(0).tostring textbox3.text = srsystem.properties("sn").item(0).tostring button3.enabled = true grab ex exception msgbox(textbox1.text & " invalid userid") textbox1.text = "" textbox1.focus() end seek

some of properties contain multiple lines , of properties not exist object, how insert multiline info in multiline textbox examaple, , how prevent code send error if attribute not exist? query property line 0 using ".item(0).tostring" , if property not exist homecoming error, need bypass those. , of import part is: how update attributes or add together new attributes object in ad?

if you're on .net 3.5 , up, should check out system.directoryservices.accountmanagement (s.ds.am) namespace. read here:

managing directory security principals in .net framework 3.5 msdn docs on system.directoryservices.accountmanagement

basically, can define domain context , find users and/or groups in ad:

// set domain context using (principalcontext ctx = new principalcontext(contexttype.domain)) { // find user userprincipal user = userprincipal.findbyidentity(ctx, "someusername"); if(user != null) { // here.... } // find grouping in question groupprincipal grouping = groupprincipal.findbyidentity(ctx, "yourgroupnamehere"); // if found.... if (group != null) { // iterate on members foreach (principal p in group.getmembers()) { console.writeline("{0}: {1}", p.structuralobjectclass, p.displayname); // whatever need members } } }

the new s.ds.am makes easy play around users , groups in ad!

vb.net active-directory vb.net-2010

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -