Find All the Message Queues on a Computer

Problem

You need to retrieve a list of the public queues in Active Directory or the private queues on a given computer.

Solution

Use the GetPublicQueues or GetPrivateQueuesByMachine methods of the System.Messaging.MessageQueue class.

Discussion

.NET allows you to examine and administer message queues and the messages they contain using the classes in the System.Messaging namespace. You can create a MessageQueue class that wraps a specific message queue by specifying the queue path in the constructor.

' Check if a queue named MyQueue exists on the current computer.
If MessageQueue.Exists(".\MyQueue") Then
    ' Show its name.
    Dim Queue As New MessageQueue(".\MyQueue")
    Console.WriteLine(Queue.QueueName)
End If

In addition, ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.