|
-
Jul 12th, 2007, 08:06 AM
#1
Thread Starter
Addicted Member
[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
-
Jul 12th, 2007, 01:39 PM
#2
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
Any ideas guys?. i know this is going to be a tuff one to solve.
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 13th, 2007, 07:05 AM
#3
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
Hi guys. I just cant work this out, i have tried everything i know...(which is very little to do this.)
I really need some help and guidance.
Thanks in advance
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 13th, 2007, 04:51 PM
#4
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 13th, 2007, 05:27 PM
#5
Re: Query Exchange Distribution Lists and display and select from a List Box.
Check out my FAQ item on reading global exchange address lists.
http://vbforums.com/showthread.php?t=406634
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 14th, 2007, 09:04 AM
#6
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
Hi RobDog888.
Thanks for the link to your code example. I finding it hard to work out how you are quering Active Directory for Exchange DL's , also i have copied your code in to a blank project but i noticed it is vb code and not vb.net , that aside any ideas how i can either get the code i have working under vbscript to work under vb.net? or i very much like the look of your code but would need some help porting it over to vb.net and then changing it to add users to the DL selected.
If you can help it would really appreciate it.
Once i have this done i am going to put all my code up in the code section as i am sure it will help everyone who wants to create a Active Directory User Creation Application.
Anyway thanks in advance for any help you can give
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 14th, 2007, 03:51 PM
#7
Re: Query Exchange Distribution Lists and display and select from a List Box.
Yes, the code is VB 6 but the CDO code is more important as its the part that allows you to read more fields in the address list then the Outlook Object Model provides. The address list is a global one stored in exchange so it doesnt readlly directly connect to it using AD. If this is ok then I may be able to port it over to .NET but may take some doing as I dont have that Exchange server available anymore.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 14th, 2007, 03:57 PM
#8
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
Hi mate. Well i guess your the expert and this may be the way to go but you might have a better idea. I will give you a bit of background and you can let me know.
This issue that i am trying to solve is part of a bigger application. The application is an app to create Active Directory users and add them to groups and set properties on their account such as address and home drive etc etc. I have everything in place and it all works 100%
My application also creates a Exchange account which is fine but what i also need is on my form a list box to query and display all the DL's, i need away of the user selecting all the DL's that they need and then as part of the user creation process add the user to said groups.
The code i posted does do that and does it very well but it is vbscript used in a HTML \ HTA application.
Anyway i hope that gives you a better idea of what i am trying to do and please advise the best way to go.
Thanks for your time and help on this.
Cheers
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 15th, 2007, 07:40 AM
#9
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
I am still struggling with this issue. I jut cant find or work out how the hell i am going to do this. No matter what i try seems to work.
Maybe it would be easier to do this in steps.
Ok can someone please help me put something to together that will connect to Active Directory and search for the Distribution lists and just display tham in a console window?
Thanks in advance
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 15th, 2007, 01:16 PM
#10
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
Hi guys. ok starting with part one.
If i use the following then it will return all groups to me on the Active Directory domain.
Code:
Dim filter As String = String.Format("(&(objectClass=group)(objectCategory=group))")
Dim entry As New DirectoryEntry("LDAP://DC=WALLACE-UK, DC=COM")
Dim searcher As New DirectorySearcher(entry, filter)
Dim Results As SearchResultCollection = searcher.FindAll
Dim str As String
For Each result As SearchResult In Results
str &= result.Path & vbCrLf
MsgBox(str)
Next
If i then change the code below to match the query that i have been using, please see first part of this thread i get all sorts of errors.
The errors i get are:
Expression expected and that is on the & on this line String.Format(&
Dim searcher As New DirectorySearcher(entry, filter) gives an error of "Overload resolution failed because no accessible 'Filter' accepts this number of arguments."
This whole section gives a syntax error
Code:
Dim filter As String = String.Format(&(&(|(&(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"
This is the code i am trying to get working
Code:
Dim filter As String = String.Format(&(&(|(&(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"
Dim entry As New DirectoryEntry("LDAP://DC=WALLACE-UK, DC=COM")
Dim searcher As New DirectorySearcher(entry, filter)
Dim Results As SearchResultCollection = searcher.FindAll
Dim str As String
For Each result As SearchResult In Results
str &= result.Path & vbCrLf
MsgBox(str)
Next
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 15th, 2007, 02:52 PM
#11
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
ok i have sorted out the filter so it is not giving me any errors now.
But when i run the code it returns nothing so something is not right
This is the changed code
Code:
Dim filter As String = String.Format("LDAP://DC=WALLACE-UK,DC=COM);&(&(|(&(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")
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 16th, 2007, 02:18 AM
#12
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 16th, 2007, 10:21 AM
#13
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
Hi guys. i am wasting to much time trying to work this out. its driving me nuts. It seemed so easy under vbscript but just cant get my head around this.
Any help will be very very much appreciated
Thanks
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 16th, 2007, 02:26 PM
#14
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 17th, 2007, 04:23 AM
#15
Thread Starter
Addicted Member
Re: Query Exchange Distribution Lists and display and select from a List Box.
Thanks
Craig Wallace
Active Directory Administrator \ Designer
SMS 2003 Administrator
Everything else Networks
-
Jul 17th, 2007, 03:01 PM
#16
Thread Starter
Addicted Member
[RESOLVED]Re: Query Exchange Distribution Lists and display and select from a
Hi guys.
Ok i have this issues fixed. One of the developers i work with solved it for me.
Here is the code to get the DL's and display them in a list box.
Thanks to RobDog for trying to help
here is the code
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim entry As New DirectoryEntry("LDAP://DC=Withers, DC=Net")
Dim filter As String = "(&(objectCategory=group)(groupType=2)(|(name=eu*)(name=uk*)(name=gn*)(name=mn*)))"
Dim searcher As New DirectorySearcher(entry, Filter, New String() {"distinguishedName", "cn"})
searcher.Sort.PropertyName = "cn"
searcher.Sort.Direction = SortDirection.Ascending
Dim Results As SearchResultCollection = searcher.FindAll
Dim a As New ArrayList
For Each result As SearchResult In Results
If result.Properties.Contains("distinguishedName") Then
Dim item As New DN(result.Properties("cn")(0).ToString, result.Properties("distinguishedName")(0).ToString)
a.Add(item)
End If
Next
With ListBoxDisplayDL
.DataSource = a
.DisplayMember = "Name"
.ValueMember = "DistinguishedName"
End With
End Sub
End Class
Public Class DN
Private _name As String
Private _distinguishedName As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Public Property DistinguishedName() As String
Get
Return _distinguishedName
End Get
Set(ByVal Value As String)
_distinguishedName = Value
End Set
End Property
Public Sub New(ByVal n As String, ByVal dn As String)
_name = n
_distinguishedName = dn
End Sub
End Class
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|