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 中的命令 ,可查看到 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);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值