[英]How to determine whether a specific Windows Update package (KB*.msu) is installed using Inno Setup?
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 . 我想知道如何确定目标计算机上是否安装了特定的Windows Update软件包,例如,假设Windows Update软件包的名称为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? 也许搞砸了注册表,或者是最干净和/或安全的方式?
Pseudo-Code: 伪代码:
[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;
Use like: 使用方式如下:
if IsKBInstalled('KB2919355') then
begin
Log('KB2919355 is installed');
end
else
begin
Log('KB2919355 is not installed');
end;
Credits: 积分:
WbemScripting.SWbemLocator
wasn't working for me when I was testing my installer on Windows 7. So I took a different approach and connected to the WUA (Windows Update Agent): 在Windows 7上测试安装程序时, WbemScripting.SWbemLocator
不适用于我。因此,我采用了另一种方法,并连接到WUA(Windows Update代理):
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;
Invocation would be as follows: 调用如下:
if IsUpdateInstalled('3020369') then
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.