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:
  1. Dim prtList As New ArrayList
  2.         Dim dirEntry As DirectoryEntry
  3.         Dim dirSearcher As DirectorySearcher
  4.         Dim resultCollection As SearchResultCollection
  5.         Dim result As SearchResult
  6.         Dim MyRow As DataRow
  7.         Dim asdf As New ArrayList
  8.  
  9.         Try
  10.             dirEntry = New DirectoryEntry("")
  11.             dirSearcher = New DirectorySearcher(dirEntry)
  12.             With dirSearcher
  13.                 .PageSize = 10
  14.                 .Filter = "objectCategory=printQueue" ' search filter
  15.                 .PropertyNamesOnly = True
  16.                 .PropertiesToLoad.Add("Name")
  17.                 .SearchScope = SearchScope.Subtree
  18.             End With
  19.             resultCollection = dirSearcher.FindAll()
  20.  
  21.             For Each result In resultCollection
  22.                 asdf.Clear()
  23.                 For Each prop As System.DirectoryServices.PropertyValueCollection In result.GetDirectoryEntry.Properties.Values
  24.                     asdf.Add(prop.Value)
  25.                 Next
  26.                 MyRow = Me.DataSet1.Tables("asdf").NewRow
  27.                 MyRow.Item("Name") = result.GetDirectoryEntry.Properties("Name").Value
  28.                 MyRow.Item("Location") = result.GetDirectoryEntry.Properties("Location").Value
  29.                 'MyRow.Item("Comment") = asdf(2)
  30.                 MyRow.Item("Model") = result.GetDirectoryEntry.Properties("DriverName").Value
  31.                 MyRow.Item("ServerName") = result.GetDirectoryEntry.Properties("ServerName").Value
  32.                 Me.DataSet1.Tables("asdf").Rows.Add(MyRow)
  33.             Next
  34.         Catch ex As Exception
  35.             MsgBox(ex.Message)
  36.         End Try
  37.         Return prtList
Thanks