WINDOWS 查看本机是否安装 vcredis
概述#
- 本文演示坏境: 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 使用函数 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);
作者: mohist
出处:https://www.cnblogs.com/pandamohist/p/16282403.html
版权:本站使用「CC BY 4.0」创作共享协议,未经作者同意,请勿转载;若经同意转载,请在文章明显位置注明作者和出处。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?