开发者

How i can check if a particular hotfix (windows update) is installed in my system?

开发者 https://www.devze.com 2023-03-05 11:36 出处:网络
I have some issues with the Riched20.dll file which is used by my application, this problem is fixed applying the KB884047 hotfix, in order to avoid problems with old windows versions, I want to detec

I have some issues with the Riched20.dll file which is used by my application, this problem is fixed applying the KB884047 hotfix, in order to avoid problems with old windows versions, I want to detect when this hotfix is applied in the system, so How i can开发者_如何学编程 check if a particular hotfix (windows update) is installed in my system using delphi?


Some time ago, I blogged about this topic search for installed windows updates using Delphi, WMI and WUA

The key is use the Windows Update Agent API

check this sample code.

//use in this way ISHotFixID_Installed('KB982799')
function  ISHotFixID_Installed(const HotFixID : string): Boolean;
var
  updateSession      : OleVariant;
  updateSearcher     : OleVariant;
  updateEntry        : OleVariant;
  updateSearchResult : OleVariant;
  UpdateCollection   : OleVariant;
  oEnum              : IEnumvariant;
  iValue             : LongWord;
begin
 result:=False;
  updateSession:= CreateOleObject('Microsoft.Update.Session');
  updateSearcher    := updateSession.CreateUpdateSearcher;
  //this line improves the performance , the online porperty indicates whether the UpdateSearcher goes online to search for updates. so how we are looking for already installed updates we can set this value to false
  updateSearcher.online:=False;
  updateSearchResult:= updateSearcher.Search(Format('IsInstalled = 1 and Type=%s',[QuotedStr('Software')]));
  UpdateCollection  := updateSearchResult.Updates;
  oEnum         := IUnknown(UpdateCollection._NewEnum) as IEnumVariant;
  while oEnum.Next(1, updateEntry, iValue) = 0 do
  begin
    Result:=Pos(HotFixID,updateEntry.Title)>0;
    updateEntry:=Unassigned;
    if Result then break;
  end;

end;
0

精彩评论

暂无评论...
验证码 换一张
取 消