简体   繁体   English

如何以编程方式检测当前系统上是否已安装MSMQ?

[英]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? 如何以编程方式检测当前系统上是否已安装MSMQ?

I am using C++, but answers in other laguages could still be helpful. 我正在使用C ++,但用其他语言回答也可能会有所帮助。

(VS2008, WinXP and up) (VS2008,WinXP及更高版本)

There's a pointer for C# here - call a method to enumerate the queues and check the error code. 有对C#的指针在这里 -调用来枚举队列,并检查错误代码的方法。

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. 我现在做的方法是尝试捕获“ GetPrivateQueuesByMachine”方法,该方法将引发带有“ MessageQueueErrorCode.ServiceNotAvailable”错误代码的异常。

Another option would be to install the MSMQ WMI Provider here and query for MSMQ object instances on the server. 另一个选择是在此处安装MSMQ WMI提供程序并在服务器上查询MSMQ对象实例。

You can simply ask COM to create an instance of the MSMQQueueInfo object. 您可以简单地要求COM创建MSMQQueueInfo对象的实例。 If it succeeds you know that MSMQ is installed. 如果成功,则说明已安装MSMQ。

#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 . 您还可以检查是否存在注册表项: HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSMQ If the key exists, MSMQ is installed. 如果密钥存在,则安装MSMQ。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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