本文介绍了如何确定是否使用Inno Setup安装了特定的Windows Update软件包(KB * .msu)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何确定目标计算机上是否安装了特定的Windows Update软件包,例如,假设Windows Update软件包的名称为 KB2919355 .

I wonder how to determine whether a specific Windows Update package is installed in the target machine, lets say for example the Windows Update package with name KB2919355.

是否存在内置功能来检查?如果没有,确定该代码将需要什么代码?也许搞砸了注册表,或者是一种最干净和/或安全的方式?

Exists a built-in feature to check that? If not, what would be the required code to determine it? Maybe messing with registry, or maybe a cleanest and/or secure way?

伪代码:

[Setup]
...

[Files]
Source: {app}\*; DestDir: {app}; Check: IsPackageInstalled('KB2919355')

[Code]
function IsPackageInstalled(packageName): Boolean;
  begin
    ...
    Result := ...;
  end;

推荐答案

function IsKBInstalled(KB: string): Boolean;
var
  WbemLocator: Variant;
  WbemServices: Variant;
  WQLQuery: string;
  WbemObjectSet: Variant;
begin
  WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  WbemServices := WbemLocator.ConnectServer('', 'root\CIMV2');

  WQLQuery := 'select * from Win32_QuickFixEngineering where HotFixID = ''' + KB + '''';

  WbemObjectSet := WbemServices.ExecQuery(WQLQuery);
  Result := (not VarIsNull(WbemObjectSet)) and (WbemObjectSet.Count > 0);
end;

使用方式:

if IsKBInstalled('KB2919355') then
begin
  Log('KB2919355 is installed');
end
  else 
begin
  Log('KB2919355 is not installed');
end;


积分:


Credits:

  • The WMI query for updates:
    How can I query my system via command line to see if a KB patch is installed?
  • Using WMI from Inno Setup:
    @TLama's answer to Inno Setup Pascal Script to search for running process.

这篇关于如何确定是否使用Inno Setup安装了特定的Windows Update软件包(KB * .msu)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 23:34