gpt4 book ai didi

windows - 如何使用 Inno Setup 确定是否安装了特定的 Windows 更新包 (KB*.msu)?

转载 作者:可可西里 更新时间:2023-11-01 09:47:30 39 4
gpt4 key购买 nike

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

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

伪代码:

[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;

学分:

关于windows - 如何使用 Inno Setup 确定是否安装了特定的 Windows 更新包 (KB*.msu)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36358221/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com