Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know programmatically whether Message Queueing is enabled on the machine or not?

Tags:

c#

.net

msmq

I know that when I try to create new MessageQueue, system throws InvalidOperationException if the Message Queuing is not enabled.

But how to know programmatically whether Message Queueing is enabled on the machine or not? I am using C# 2.0 & C# 4.0 in two different code bases.

like image 870
Learner Avatar asked May 20 '11 07:05

Learner


3 Answers

You can use the System.ServiceProcess for this one, but first you need to add reference to your project the Service.ServiceProcess, and you can retrieve all the services and get their status like this:

List<ServiceController> services = ServiceController.GetServices().ToList();
ServiceController msQue = services.Find(o => o.ServiceName == "MSMQ");
if (msQue != null) {
    if (msQue.Status == ServiceControllerStatus.Running) { 
        // It is running.
    }
} else { // Not installed? }
like image 135
Peyton Crow Avatar answered Dec 14 '22 23:12

Peyton Crow


Answering little late, but if you are scripting fan Powershell is at your help. To get status update on numbers, use following script:

$queues = Get-WmiObject Win32_PerfFormattedData_msmq_MSMQQueue
$queues | ft -property Name,MessagesInQueue

This will show you name of queue and number of items in each queue. Hope this will help someone someday. :D

like image 22
Sanjay Zalke Avatar answered Dec 14 '22 22:12

Sanjay Zalke


How to tell if MSMQ is installed

like image 30
John Breakwell Avatar answered Dec 14 '22 23:12

John Breakwell