在使用 Inno Setup 制作应用程序安装包时,可以使用以下代码检测某个 Windows 补丁更新包是否已经安装:
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;
测试有用,感谢分享!