Detect Chrome as browser associated with html files in Windows

∥☆過路亽.° 提交于 2019-12-01 05:39:25

If you have an actual full path to an existing file on disk, you can use FindExecutable instead. It's easier, and doesn't require access to the registry, but it does require that an actual file exists.

Here's a console app for XE2 that demonstrates use:

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  SysUtils, ShellAPI, Windows;

var
  Buffer: array[0..MAX_PATH] of Char;
  Res: Integer;

begin
  FillChar(Buffer, SizeOf(Buffer), #0);
  Res := FindExecutable(PChar('C:\Path\File.html'), nil, Buffer);
  if Res > 32 then
    Writeln('Executable is ' + Buffer)
  else
    WriteLn(SysErrorMessage(Res));
  Readln;
end.

The method you show will work, but FindExecutable is easier (less code) and works on XP and above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!