检查是否在PC上安装了Outlook

时间:2009-09-02 07:08:34

标签: c++ outlook

有没有办法可以编程方式检测微软是否存在 Outlook(其任何版本)安装在PC上。我必须在非托管的c ++中完成它。

4 个答案:

答案 0 :(得分:2)

检查是否存在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE,其“Default”值包含exe的路径。

答案 1 :(得分:2)

在MSDN is an example of how to detect Outlook版本(或者根本不安装Outlook)。以下是该示例的美化版本:

#include <Windows.h>
#include <Msi.h>

#include "stdafx.h"

static int compareOutlookVersion(const TCHAR* exe)
{
    const TCHAR outlookRegister[][MAX_PATH] = {
        TEXT("{E83B4360-C208-4325-9504-0D23003A74A5}"), // Outlook 2013
        TEXT("{1E77DE88-BCAB-4C37-B9E5-073AF52DFD7A}"), // Outlook 2010
        TEXT("{24AAE126-0911-478F-A019-07B875EB9996}"), // Outlook 2007
        TEXT("{BC174BAD-2F53-4855-A1D5-0D575C19B1EA}")  // Outlook 2003
    };
    const int outlookVersions[] = {
         2013,
         2010,
         2007,
         2003 
    };
    DWORD pathLength = 0;

    for (int i = 0; i < (sizeof(outlookVersions) / sizeof(outlookVersions[0])); i++)

    if (ERROR_SUCCESS ==
        MsiProvideQualifiedComponent(
            outlookRegister[i],
            exe,
            (DWORD) INSTALLMODE_DEFAULT,
            NULL,
            &pathLength
        )) {
        return outlookVersions[i];
    }

    return 0;
}

int getOutlookVersion(int* bits)
{
    int version;

    *bits = 32;
    version = compareOutlookVersion(TEXT("outlook.exe"));
    if (version) {
        return version;
    }

    *bits = 64;
    version = compareOutlookVersion(TEXT("outlook.x64.exe"));
    if (version) {
        return version;
    }

    *bits = 0;
    return 0; // No Outlook found.
}

int _tmain(int argc, _TCHAR* argv[])
{
    HRESULT result;
    int version;
    int bits;

    version = getOutlookVersion(&bits);

    if (version) {
        printf("Outlook %d, %d bit\n", version, bits);
    } else {
        printf("No Outlook found.\n");
    }

    return 0;
}

答案 2 :(得分:1)

Outlook公开COM接口,只检查该接口?

答案 3 :(得分:1)

MSalters,你的意思是类似下面的代码:

::CoInitialize(NULL);
_ApplicationPtr pApp;
HRESULT hr;
hr = pApp.CreateInstance(__uuidof(Outlook::Application));
if ((pApp == NULL) || FAILED(hr))
{
    return false;
}