简体   繁体   中英

How can I programmatically detect if MSMQ has been installed on the current system?

How can I programatically detect if MSMQ has been installed on the current system?

I am using C++, but answers in other laguages could still be helpful.

(VS2008, WinXP and up)

There's a pointer for C# here - call a method to enumerate the queues and check the error code.

The way I'm doing it now is to try-catch the 'GetPrivateQueuesByMachine' method, that will throw an exception with the 'MessageQueueErrorCode.ServiceNotAvailable' error code.

Another option would be to install the MSMQ WMI Provider here and query for MSMQ object instances on the server.

You can simply ask COM to create an instance of the MSMQQueueInfo object. If it succeeds you know that MSMQ is installed.

#include <atlbase.h>
#include <mqoai.h>

#include <iostream>
using namespace std;

int main()
{
    auto error = CoInitializeEx(0, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);

    if (FAILED(error))
    {
        wcout << L"You've got bigger problems" << endl;
    }
    else
    {
        CComPtr<IMSMQQueueInfo> info;

        error = info.CoCreateInstance(__uuidof(MSMQQueueInfo));

        if (SUCCEEDED(error))
        {
            wcout << L"MSMQ is installed" << endl;
        }
    }
}

You also can check for the existence of the registry key: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSMQ . If the key exists, MSMQ is installed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM