WINDOWS 檢視本機是否安裝 vcredis
阿新 • • 發佈:2022-05-17
概述
- 本文演示壞境: win11 + vs2019 / vs2015
- power shell (管理員)
步驟1
- 開啟powerhsell 管理員模式, 查詢本機安裝的vcredis的版本, 比如, 下面的程式碼查詢本機的vc2019 redis的唯一ID
Get-WmiObject -Class Win32_Product -Filter "Name LIKE '%Visual C++ 2019%'"
- 將 上面程式碼中的2019換成你想要查詢的vc++版本即可, 比如2010, 2012, 2015, 2017 , 2019 2022......
步驟2
- 鍵入 步驟1 中的命令 ,可檢視到 ID
不會查詢? 再看一個例子
- 查詢 vc++ 2010 的再發行包
程式碼中檢查是否包含再發行包
1 使用函式 MsiQueryProductState
- 改函式的引數是字串, 這裡可以傳遞 powershell中查詢的唯一ID
標頭檔案
#include <msi.h>
庫檔案
#pragma comment(lib, "Msi.lib")
MsiQueryProductState 返回值
INSTALLSTATE_NOTUSED = -7, // component disabled INSTALLSTATE_BADCONFIG = -6, // configuration data corrupt INSTALLSTATE_INCOMPLETE = -5, // installation suspended or in progress INSTALLSTATE_SOURCEABSENT = -4, // run from source, source is unavailable INSTALLSTATE_MOREDATA = -3, // return buffer overflow INSTALLSTATE_INVALIDARG = -2, // invalid function argument INSTALLSTATE_UNKNOWN = -1, // unrecognized product or feature INSTALLSTATE_BROKEN = 0, // broken INSTALLSTATE_ADVERTISED = 1, // advertised feature INSTALLSTATE_REMOVED = 1, // component being removed (action state, not settable) INSTALLSTATE_ABSENT = 2, // uninstalled (or action state absent but clients remain) INSTALLSTATE_LOCAL = 3, // installed on local drive INSTALLSTATE_SOURCE = 4, // run from source, CD or net INSTALLSTATE_DEFAULT = 5, // use default, local or source
用法 範例
INSTALLSTATE ret = MsiQueryProductState(str);
/// INSTALLSTATE_DEFAULT- 已經存在, 否則, 不存在
if (INSTALLSTATE_DEFAULT != ret)
{
//str_result = L"false";
str_result.Format(L"index=%d----%d", index, ret);
}
else
{
str_result.Format(L"index=%d----true", index);
}
一個c++程式碼使用範例
UI示例
核心程式碼
static int index = 0; CString str; // 讀取介面輸入的唯一ID:{XXXX-XXX-XXX-XXX} edit_src.GetWindowText(str); if (TRUE == str.IsEmpty()) { return; } CString str_result; /// str - 唯一ID INSTALLSTATE ret = MsiQueryProductState(str); /// INSTALLSTATE_DEFAULT- 已經存在, 否則, 不存在 if (INSTALLSTATE_DEFAULT != ret) { //str_result = L"false"; str_result.Format(L"index=%d----%d", index, ret); } else { str_result.Format(L"index=%d----true", index); } ++index; edit_result.SetWindowText(str_result);