Jump to content

Recommended Posts

Hi Team,

Two questions..

1.  What is the best reference for Windows APIs that Delphi can access/use?

2.  Is there a Windows API that tells if there are any OS updates waiting to be installed?

 

Regards & TIA,

Ian

 

Share this post


Link to post
6 minutes ago, Ian Branch said:

What is the best reference for Windows APIs that Delphi can access/use?

Delphi can access all Windows APIs and the best reference is MSDN. 

  • Like 1

Share this post


Link to post
1 hour ago, Ian Branch said:

Is there a Windows API that tells if there are any OS updates waiting to be installed?

https://docs.microsoft.com/en-us/windows/win32/api/_wua/

 

You should almost be able to follow this C# example

https://stackoverflow.com/questions/64203306/c-sharp-get-pending-windows-updates-updates-that-cant-be-found

 

Also you might prototype it in powershell just to make sure you are getting the results you want before you spend time writing Delphi code.

here is almost a step by step

https://mcpmag.com/articles/2016/06/23/finding-pending-updates.aspx

Share this post


Link to post
Posted (edited)

Hi Team, thank you for your inputs.

I am using D11.1.1, Win 11 64 bit.

I freely confess I am playing in/with something I know nothing about and don't expect to need again.

I found an article from 'The road to Delphi', https://theroadtodelphi.com/2011/03/02/search-for-installed-windows-updates-using-delphi-wmi-and-wua/

From this I created this test project as a start point..

unit Unit24;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Winapi.ActiveX,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.Win.ComObj;

type
  TForm24 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    function ISHotFixID_Installed(const HotFixID: string): Boolean;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form24: TForm24;
  updateSession: OleVariant;
  updateSearcher: OleVariant;
  updateEntry: OleVariant;
  updateSearchResult: OleVariant;
  UpdateCollection: OleVariant;
  oEnum: IEnumvariant;
  iValue: LongWord;

implementation

{$R *.dfm}

//use in this way ISHotFixID_Installed('KB982799')
function TForm24.ISHotFixID_Installed(const HotFixID: string): Boolean;
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;

procedure TForm24.Button1Click(Sender: TObject);
begin
if ISHotFixID_Installed('KB5014650') then ShowMessage('KB Found.') else ShowMessage('KB Not Found.') ;
end;

end.

A couple of interesting things..

1.  Whenever I go to edit this line Delphi hangs up.  No keyboard or mouse response in the IDE.  😞 Although Task Manager says it is busy, I have left it for 30+ minutes and it still doesn't return.

if ISHotFixID_Installed('KB5014650') then ShowMessage('KB Found.') else ShowMessage('KB Not Found.') ;

image.thumb.png.60c5638c3d68eb8c5f820047c6c11eb3.png

 

2.  KB5014650 IS installed on the PC but the button1 function tells me it isn't. 😞

 

Again, this is my first step.  From here I had hoped to implement the search function to see what has been downloaded but not installed.

 

OK.  It is probably me, what have I missed?

Or, is there an issue either with Delphi or Win 11 or both? 

Perhaps the fact that I am trying to use it on a 64bit OS?

 

Appreciate any assistance/guidance.

 

Regards & TIA,

Ian

Edited by Ian Branch

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×