|
-
Feb 14th, 2007, 03:06 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] System.DirectoryServices - Property names? VB.Net 2003
I am trying to imitate the Find Printers form in the Print Wizard. This loads my dataset with all the values I need except for "Comments", and "Name" also includes the server name. I added the ArrayList asdf for debugging, which allowed me to look at each property that was returned. However, I must name these explicitly, and Properties("Comment") and Properties("Comments") don't return the comment. I commented it out, but I found that if a Comment does exist, it will be the second property. So, my question is, does anyone have a list of the properties that can possibly be returned that pertain to printers? Also, is there any clever code that I could use to print out the names of these properties? I have tried, but for the life of me I can't get it to work.
VB Code:
Dim prtList As New ArrayList
Dim dirEntry As DirectoryEntry
Dim dirSearcher As DirectorySearcher
Dim resultCollection As SearchResultCollection
Dim result As SearchResult
Dim MyRow As DataRow
Dim asdf As New ArrayList
Try
dirEntry = New DirectoryEntry("")
dirSearcher = New DirectorySearcher(dirEntry)
With dirSearcher
.PageSize = 10
.Filter = "objectCategory=printQueue" ' search filter
.PropertyNamesOnly = True
.PropertiesToLoad.Add("Name")
.SearchScope = SearchScope.Subtree
End With
resultCollection = dirSearcher.FindAll()
For Each result In resultCollection
asdf.Clear()
For Each prop As System.DirectoryServices.PropertyValueCollection In result.GetDirectoryEntry.Properties.Values
asdf.Add(prop.Value)
Next
MyRow = Me.DataSet1.Tables("asdf").NewRow
MyRow.Item("Name") = result.GetDirectoryEntry.Properties("Name").Value
MyRow.Item("Location") = result.GetDirectoryEntry.Properties("Location").Value
'MyRow.Item("Comment") = asdf(2)
MyRow.Item("Model") = result.GetDirectoryEntry.Properties("DriverName").Value
MyRow.Item("ServerName") = result.GetDirectoryEntry.Properties("ServerName").Value
Me.DataSet1.Tables("asdf").Rows.Add(MyRow)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return prtList
Thanks
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Feb 14th, 2007, 03:51 PM
#2
Re: System.DirectoryServices - Property names? VB.Net 2003
Try this sub... Just pass in a directory entry
VB Code:
Private Sub DisplayPropertyNames(ByVal de As DirectoryEntry)
Dim output As String = ""
Dim IColl As System.Collections.ICollection = de.Properties.PropertyNames
Dim IEnum As IEnumerator = IColl.GetEnumerator
While IEnum.MoveNext = True
output &= IEnum.Current.ToString & ControlChars.NewLine
End While
MsgBox(output)
End Sub
-
Feb 14th, 2007, 04:32 PM
#3
Thread Starter
Fanatic Member
Re: System.DirectoryServices - Property names? VB.Net 2003
Thanks, Stanav. I just had to change it a little and send it a property collection. And I also sent an array on the values themselves, just so I could see them side by side.
VB Code:
Private Sub DisplayPropertyNames(ByVal pv As PropertyCollection, ByRef PropValues As ArrayList)
Dim i As Integer = 0
Dim output As String = ""
Dim IColl As System.Collections.ICollection = pv.PropertyNames
Dim IEnum As IEnumerator = IColl.GetEnumerator
While IEnum.MoveNext = True
output &= IEnum.Current.ToString & " = " & PropValues.Item(i).ToString & ControlChars.NewLine
i += 1
End While
MsgBox(output)
End Sub
I am getting closer now, but I really need to look at some attributes or something so I can tell if it is a barcode printer or not. Hopefully that can be determined from this information. Thanks again.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
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
|