Results 1 to 16 of 16

Thread: [RESOLVED]Query Exchange Distribution Lists and display and select from a List Box.

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    148

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

    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.

    Code:
    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.

    Code:
    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
    Last edited by cjwallace; Jul 17th, 2007 at 05:06 PM.
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width