|
-
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..."
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
|