Results 1 to 3 of 3

Thread: [RESOLVED] System.DirectoryServices - Property names? VB.Net 2003

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Resolved [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:
    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
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: System.DirectoryServices - Property names? VB.Net 2003

    Try this sub... Just pass in a directory entry
    VB Code:
    1. Private Sub DisplayPropertyNames(ByVal de As DirectoryEntry)
    2.         Dim output As String = ""
    3.         Dim IColl As System.Collections.ICollection = de.Properties.PropertyNames
    4.         Dim IEnum As IEnumerator = IColl.GetEnumerator
    5.         While IEnum.MoveNext = True
    6.             output &= IEnum.Current.ToString & ControlChars.NewLine
    7.         End While
    8.         MsgBox(output)
    9.     End Sub

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    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:
    1. Private Sub DisplayPropertyNames(ByVal pv As PropertyCollection, ByRef PropValues As ArrayList)
    2.         Dim i As Integer = 0
    3.         Dim output As String = ""
    4.         Dim IColl As System.Collections.ICollection = pv.PropertyNames
    5.         Dim IEnum As IEnumerator = IColl.GetEnumerator
    6.         While IEnum.MoveNext = True
    7.             output &= IEnum.Current.ToString & " = " & PropValues.Item(i).ToString & ControlChars.NewLine
    8.             i += 1
    9.         End While
    10.         MsgBox(output)
    11.     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
  •  



Click Here to Expand Forum to Full Width