【问题标题】:How to determine whether a specific Windows Update package (KB*.msu) is installed using Inno Setup?如何确定是否使用 Inno Setup 安装了特定的 Windows 更新包 (KB*.msu)?
【发布时间】:2016-04-01 13:56:24
【问题描述】:

我想知道如何确定目标计算机中是否安装了特定的 Windows Update 包,例如名称为 KB2919355 的 Windows Update 包。

是否存在用于检查的内置功能?如果不是,确定它所需的代码是什么?也许会弄乱注册表,或者可能是最干净和/或安全的方式?

伪代码:

[Setup]
...

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

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

【问题讨论】:

    标签: windows installation inno-setup pascalscript


    【解决方案1】:
    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;
    

    学分:

    【讨论】:

    • 您可以将"localhost" 替换为"."。它更快
    • @user240217 或者实际上是一个空字符串。谢谢。
    【解决方案2】:

    当我在 Windows 7 上测试我的安装程序时,WbemScripting.SWbemLocator 不适合我。所以我采取了不同的方法并连接到 WUA(Windows 更新代理):

    function IsUpdateInstalled(KB: String): Boolean;
    var
      UpdateSession: Variant;
      UpdateSearcher: Variant;
      SearchResult: Variant;
      I: Integer;
    begin
      UpdateSession := CreateOleObject('Microsoft.Update.Session');
      UpdateSearcher := UpdateSession.CreateUpdateSearcher()
      SearchResult := UpdateSearcher.Search('IsInstalled=1')
      for I := 0 to SearchResult.Updates.Count - 1 do
      begin
        if SearchResult.Updates.Item(I).KBArticleIDs.Item(0) = KB then
        begin
          Result := true;
          Exit;
        end;
      end;
      Result := false;
    end;
    

    调用如下:

    if IsUpdateInstalled('3020369') then
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-07
      • 2011-05-05
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 2012-06-05
      • 2022-10-22
      • 2020-04-10
      相关资源
      最近更新 更多