Enumerate all outgoing Queues in MSMQ, C#
Asked Answered
F

1

10

Using C# and .NET 3.5, how can I get a listing of all outgoing queues in MSMQ? I found this article about it but as you can see below I do not have the COM entry for Microsoft Message Queue 3.0 Object Library...

I accidentally the Microsoft Message Queue 3.0 Object Library

So how can I get the current outgoing queue listing? I figured there must be a way since I can see them in Computer Management...

Computer Management + MSMQ

What can I do?

Ferdinand answered 31/5, 2011 at 18:10 Comment(0)
J
3

Two good places to start I think would be these:

http://msdn.microsoft.com/en-us/library/ms703173%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/ms711378%28v=vs.85%29.aspx

I'll see if I can work up some code.


Perhaps not, those look old, still looking.


Heres some WScript that will show them to you, still looking for .Net code:

Dim Locator
Set Locator = CreateObject("WbemScripting.SWbemLocator")
Dim objs
Set Service = Locator.ConnectServer(".", "root\cimv2")
Set objs = Service.ExecQuery("Select * From Win32_PerfRawData_MSMQ_MSMQQueue")
For Each object In objs
    WScript.Echo "Name: " & object.Name
Next 

using System.Management;
namespace TestMSMQStuff
{
    class Program
    {

        static void Main(string[] args)
        {

            System.Management.SelectQuery q = new SelectQuery("Select * From Win32_PerfRawData_MSMQ_MSMQQueue");
            ManagementObjectSearcher s = new ManagementObjectSearcher(q);
            foreach (var r in s.Get())
            {
                Console.WriteLine(r.Properties["Name"].Value);
            }
        }
    }
}

Looks like all the outgoing queues start with "os:"

Need to references System.Management and System.Management.Instrumentation

Juta answered 31/5, 2011 at 18:18 Comment(7)
The issue I had with those (at least as far as I could tell) was that I had to add the COM reference. However, in my Visual Studio 2008 there is no entry for the Microsoft Message Queue 3.0 Object Library. I am not sure how to correct this state, or how to work around it. But yes, those two articles reference similar methods I had listed in the linked articleFerdinand
Is there a way to Interop this with C#? If there is how would I do it?Ferdinand
I see your code update, I'll be trying it out and reporting back!Ferdinand
...ok well that got me a list of format names I needed. That's a great start. However, can you explain the "science" of your code snippet to me? I've been trying to get a solution for this, and I'd like to know the reasoning about your code. I'd be more than happy to mark your answer correct after that.Ferdinand
Alright this makes sense now that I have learned more about WMI. Thank you for this awesome answer :)Ferdinand
Is there no way to do this using the C# MSMQ library? msdn.microsoft.com/en-us/library/…Inconsistent
@BenjaminSussman from what I can find it's still either COM or WMI to get at the outgoing queuesJuta

© 2022 - 2024 — McMap. All rights reserved.