Query Exchange Distribution Lists and display and select from a List Box.

cjwallace

Member
Joined
May 5, 2007
Messages
13
Programming Experience
Beginner
Guys. I have this bit of code that i was using in a vbscript \ HTML HTA application.

What happens is when the hta opened it would display all of the distribution lists from the query in a multi select list box. The person using the script would then multi select the Distribution lists and it would then add the user in question to all of them that were selected.

I really need some help trying to convert this over to .net and i am just stuck big time and unsure where to start.

Please see both bits to this code that i have taken from my vbscript.

Thanks in advance.

VB.NET:
Dim strQuery, objConnection, objCommand, objRecordSet, strHTML, strDomain
       Dim objRoot
       
       Set objRoot = GetObject("LDAP://RootDSE")
       strDomain = objRoot.Get("DefaultNamingContext")        
       strQuery = "<LDAP://" & strDomain & ">;(&(&(|(&(objectCategory=person)(objectSid=*)" & _
                  "(!samAccountType:1.2.840.113556.1.4.804:=3))(&(objectCategory=person)(!objectSid=*))" & _
                  "(&(objectCategory=group)(groupType:1.2.840.113556.1.4.804:=14)))(& (mailnickname=*)" & _
                  "(| (objectCategory=group) ))));name,distinguishedname;subtree"
       Set objConnection = CreateObject("ADODB.Connection")
       Set objCommand = CreateObject("ADODB.Command")
       objConnection.Open "Provider=ADsDSOObject;"
       objCommand.ActiveConnection = objConnection
       objCommand.CommandText = strQuery
       objCommand.Properties("Sort On") = "Name"
       Set objRecordSet = objCommand.Execute
       
       strHTML = "<select size='10' id='distributionlists' multiple>"
       Do Until objRecordSet.EOF
           strHTML = strHTML & "<option value='" & objRecordSet.Fields("distinguishedname") & "'>" & _
           objRecordSet.Fields("name") &"</option>"
           objRecordSet.MoveNext
       Loop
       strHTML = strHTML & "</Select>"
       
       objConnection.Close
       window.document.getElementById("DisplayDL").innerHTML = strHTML

Then i have this bit of code that depending on what Distribution Lists are selected will add the user to each one.

VB.NET:
Dim i,objGroup
 For i = 0 To (distributionlists.Options.Length - 1) 
 If (distributionlists.Options(i).Selected) Then 

	Set objGroup = GetObject("LDAP://" & distributionlists.Options(i).Value)
  	objGroup.PutEx ADS_PROPERTY_APPEND, "member", Array("cn=" & strCN _
& ",OU=" & sDepartment & ",OU=" & WithersOffice.Value & ",OU=USERS,OU=EUROPE,OU=WITHERS,dc=WITHERS,dc=NET")
  	objGroup.SetInfo
 
	End If 
 Next 

End If
 
Hi guys. I am pulling my hair out with this one. I just cant seem to get it to work or work out what i need to do.

Any help anyone can give would be fab.

Thanks in advance
 
Back
Top