WINDOWS 查看本机是否安装 vcredis

概述#

  • 本文演示坏境: win11 + vs2019 / vs2015
  • power shell (管理员)

步骤1#

  • 打开powerhsell 管理员模式, 查询本机安装的vcredis的版本, 比如, 下面的代码查询本机的vc2019 redis的唯一ID
Copy Highlighter-hljs
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

头文件#

Copy Highlighter-hljs
#include <msi.h>

库文件#

Copy Highlighter-hljs
#pragma comment(lib, "Msi.lib")

MsiQueryProductState 返回值#

Copy Highlighter-hljs
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

用法 范例#

Copy Highlighter-hljs
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示例#

核心代码#

Copy Highlighter-hljs
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);
posted @   mohist  阅读(3008)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示
CONTENTS