如何检测Visual C ++ 2013可再发行组件包

时间:2015-03-06 13:43:17

标签: c++ visual-studio-2013

我如何检测" Visual C ++ 2013可再发行"已安装?

以下c ++代码正确检测到2010 redist:

    // Visual C++ 2010 Redist detection...
    INSTALLSTATE state = pMsiProc( _T("{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}") );
    if(state == INSTALLSTATE_DEFAULT)
    {
        // Visual C++ 2010 redist installed.
    }

我希望在2013 redist中使用相同类型的代码,但无论是否安装了软件包,INSTALLSTATE都会返回INSTALLSTATE_DEFAULT。谁知道为什么?

    // call MsiQueryProductStateW...
    INSTALLSTATE state = pMsiProc(_T("{13A4EE12-23EA-3371-91EEEFB36DDFFF3E}"));
    // 
    if ((state == INSTALLSTATE_DEFAULT || state == INSTALLSTATE_LOCAL) 
    {
        // 2013 redist is installed.
    }

2 个答案:

答案 0 :(得分:1)

您是否使用x86架构?如果没有,代码就不同了:https://allthingsconfigmgr.wordpress.com/2013/12/17/visual-c-redistributables-made-simple/

答案 1 :(得分:0)

作为替代方案,您可以枚举注册表,查看以下标记的“ Displayname ”键:“Microsoft”,“Visual”,“C ++”,“Redistributable”。您可以使用以下内容来确定子键是否是您所追求的......

//  search for valid tokens to indicate this is a redistributable.
resToken = name.Tokenize (_T(" "), curPos);
while (resToken != _T(""))
    {
    if (resToken == _T("Microsoft"))
        tokenCount |= 0x01;
    if (resToken == _T("Visual"))
        tokenCount |= 0x02;
    if (resToken == _T("C++"))
        tokenCount |= 0x04;
    if (resToken == _T("Redistributable"))
        tokenCount |= 0x08;
    resToken = name.Tokenize (_T(" "), curPos);
    }

//  check for matching tokens in the Display Name.
if (tokenCount == 0x0f)
    {

只需在“ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall ”开始搜索,并枚举上述值的所有子键。您还需要检查32和64位的配置单元。

相关问题