Locating a Public Queue

Public queues can be located by running a query on the queues registered in Active Directory. A query can be based on the queue's identifier, its label, the type of service it provides, when it was created, or the last time the queue's properties were modified.

A query is made by calling the MSMQQuery object's LookupQueue method. When the query is finished, the returned MSMQQueueInfos object references all the queues located by the query.

    To run a query
  1. Determine the search criteria for the query. When locating queues by label, type of service, create time, or modify time, you can also specify a relationship parameter. For example, when using the queue's create time as the search criteria, you can also use the create time's relationship parameter (RelCreateTime) to locate all the queues that were created before, after, or on a specific date.
  2. Call LookupQueue.
    Set qinfos = query.LookupQueue(Label:="Test Queue")
     
  3. Call Reset on the returned MSMQQueueInfos object. Although this is not required, it guarantees that the cursor is looking at the first queue in the returned set.
    qinfos.Reset
     
  4. Look at the queues in the query. In the example below, this is done by calling Next to point to the first queue in the query, followed by a common While loop containing another call to Next.
    Set qinfo = qinfos.Next
    
    While Not qinfo Is Nothing
        MsgBox "I found a Test Queue! its Format name is: " + qinfo.FormatName
        Set qinfo = qinfos.Next
    Wend
     

Example

This example assumes that at least one queue whose label is Test Queue already exists. It runs a query for the test queues, displaying the format name of each queue it finds.

To try this example using Microsoft® Visual Basic® (version 5.0), paste the code into the Declaration section of a form, run the example, and click the form.

Dim query As New MSMQQuery
Dim qinfos As MSMQQueueInfos
Dim qinfo As MSMQQueueInfo
Dim Response As String

Private Sub Form_Click()

   Set qinfos = query.LookupQueue(Label:="Test Queue")
   qinfos.Reset
   Set qinfo = qinfos.Next

   While Not qinfo Is Nothing
      MsgBox "I found a Test Queue! its Format name is: " + qinfo.FormatName
      Set qinfo = qinfos.Next
   Wend
    
End Sub