检测VC库是否存在

本篇文章整理自网络,所以没有标注原创,原创我也找不到

通过MSI的API来查询 ,参见MSDN说明 MsiQueryProductState

MsiQueryProductState的输入参数为产品ID,其返回值为产品安装状态,若返回值为INSTALLSTATE_DEFAULT则表示已安装。

返回值及安装状态:

INSTALLSTATE 返回值 产品的安装状态 INSTALLSTATE_UNKNOWN -1 该产品未被广告或安装
INSTALLSTATE_ADVERTISED 1 该产品已广告但未安装
INSTALLSTATE_ABSENT 2 该产品为不同的用户安装
INSTALLSTATE_DEFAULT 5 该产品已为当前用户安装

#include "stdafx.h"
#include <Windows.h> 
#include <stdio.h>
#include <msi.h>
#pragma comment(lib,"Msi.lib")

int main()
{
	INSTALLSTATE install_state;
	install_state = MsiQueryProductState(L"{071c9b48-7c32-4621-a0ac-3f809523288f}");  //for x64 runtime
	if (install_state == INSTALLSTATE_DEFAULT)
	{
		::MessageBox(NULL, L"已经安装", L"Success", MB_OK | MB_ICONINFORMATION);
	}
	else
	{
		::MessageBox(NULL, L"请安装", L"Error", MB_OK | MB_ICONERROR);
	}
	getchar();
}

另外提供他们在注册表里的键值

Visual C++ 2005 runtime files
Visual C++ 2005 Redistributable Package (x86) - {A49F249F-0C91-497F-86DF-B2585E8E76B7}
Visual C++ 2005 Redistributable Package (x64) - {6E8E85E8-CE4B-4FF5-91F7-04999C9FAE6A}
Visual C++ 2005 Redistributable Package (ia64) - {03ED71EA-F531-4927-AABD-1C31BCE8E187}
 
Visual C++ 2005 SP1 runtime files
 
Visual C++ 2005 SP1 Redistributable Package (x86) - {7299052B-02A4-4627-81F2-1818DA5D550D}
Visual C++ 2005 SP1 Redistributable Package (x64) - {071C9B48-7C32-4621-A0AC-3F809523288F}
Visual C++ 2005 SP1 Redistributable Package (ia64) - {0F8FB34E-675E-42ED-850B-29D98C2ECE08}
 
Visual C++ 2005 SP1 ATL Security Update runtime files
Visual C++ 2005 SP1 ATL Security Update Redistributable Package (x86) - {837B34E3-7C30-493C-8F6A-2B0F04E2912C}
Visual C++ 2005 SP1 ATL Security Update Redistributable Package (x64) - {6CE5BAE9-D3CA-4B99-891A-1DC6C118A5FC}
Visual C++ 2005 SP1 ATL Security Update Redistributable Package (ia64) - {85025851-A784-46D8-950D-05CB3CA43A13}
 
Visual C++ 2008 runtime files
* VC 9.0 (x86) - {FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4} 
* VC 9.0 (x64) - {350AA351-21FA-3270-8B7A-835434E766AD}
* VC 9.0 (ia64) - {2B547B43-DB50-3139-9EBE-37D419E0F5FA} 
 
Visual C++ 2008 SP1 runtime files
* VC 9.0 SP1 (x86) - {9A25302D-30C0-39D9-BD6F-21E6EC160475}
* VC 9.0 SP1 (x64) - {8220EEFE-38CD-377E-8595-13398D740ACE}
* VC 9.0 SP1 (ia64) - {5827ECE1-AEB0-328E-B813-6FC68622C1F9}
 
Visual C++ 2008 SP1 ATL Security Update runtime files
* VC 9.0 SP1 ATL (x86) - {1F1C2DFC-2D24-3E06-BCB8-725134ADF989}
* VC 9.0 SP1 ATL (x64) - {4B6C7001-C7D6-3710-913E-5BC23FCE91E6}
* VC 9.0 SP1 ATL (ia64) - {977AD349-C2A8-39DD-9273-285C08987C7B}
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页