Hot to check if WebView2 is installed?

To prevent the user from receiving error messages when opening the viewers, I created a function that checks if WebView2 is installed (needs to work on both Windows 32 and Windows 64).

Below is the function I created:

function IsWebView2Installed: Boolean;
var
  Reg: TRegistry;
begin
  Result := False;
  Reg := TRegistry.Create(KEY_READ);
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKeyReadOnly('SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}') then
    Begin
        Result := True;
        Exit;
    End;
    if Reg.OpenKeyReadOnly('Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}') then
    Begin
        Result := True;
        Exit;
    End;
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKeyReadOnly('Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}') then
    Begin;
        Result := True;
        Exit;
    end;
  finally
    Reg.Free;
  end;
end;

I tested it on Windows 10 and Windows 11 (32 and 64 bit) and it worked correctly.

Does anyone have a similar function that is better (and more secure) than this that they can share?

Thank you

In a similar way, you can detect the version of the engine available. If the browser version string is empty, the runtime is not found.