将Chrome浏览器与Windows中的html文件相关联的浏览器 [英] Detect Chrome as browser associated with html files in Windows

查看:246
本文介绍了将Chrome浏览器与Windows中的html文件相关联的浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们提供Flash应用程序在本地(Windows)硬盘上安装的Flash教程视频。我们的应用程序使用ShellExecute打开嵌入其中的html文件(与任何与html文件相关的浏览器)。



显然,Chrome的更新的Flash播放器有一个错误无法播放本地文件(但网络上的文件是正常的。)



(坦白说,我很惊讶, Google已经修复了,似乎对我来说是一个大人物,但可能没有很多人从网络以外的地方播放Flash?)



在Chrome上的about:plugins屏幕上,但是我们不能要求我们的用户这样做。以下是有关解决方法的讨论: http://techsmith.custhelp.com/ app / answers / detail / a_id / 3518



我想向用户提供打开我们的html文件IE的选项。如果Chrome是他们的默认浏览器,那么我会显示一个复选框,表示尴尬,如如果我们的教程视频无法播放,请选中此框以在IE中尝试。



这个XE2代码(从两年前的这个版本开始,就是这样:链接)仍然合理?

 如果pos('CHROME',UpperCase(GetAssociation('C:\Path\File.html'))> 0然后
// Chrome是默认浏览器

函数GetAssociation(const DocFileName:string):string;
var
FileClass:string;
注册表:TRegistry;
begin
结果:='';
注意:= TRegistry.Create(KEY_EXECUTE);
Reg.RootKey:= HKEY_CLASSES_ROOT;
FileClass:='';
如果Reg.OpenKeyReadOnly(ExtractFileExt(DocFileName)))
begin
FileClass:= Reg.ReadString('');
Reg.CloseKey;
end;
如果FileClass<> ''然后开始
如果Reg.OpenKeyReadOnly(FileClass +'\Shell\Open\Command')然后
开始
结果:= Reg.ReadString('');
Reg.CloseKey;
结束
结束
Reg.Free;
结束


解决方案

如果您有一个现有文件的实际完整路径在磁盘上,您可以使用 FindExecutable 。这很容易,并且不需要访问注册表,但它确实需要一个实际的文件存在。



这是XE2的控制台应用程序,演示使用: p>

 程序Project1; 

{$ APPTYPE CONSOLE}

{$ R * .res}

使用
SysUtils,ShellAPI,Windows;

var
缓冲区:数组[0..MAX_PATH]的Char;
Res:整数;

begin
FillChar(Buffer,SizeOf(Buffer),#0);
Res:= FindExecutable(PChar('C:\Path\File.html'),nil,Buffer);
如果Res> 32然后
Writeln('Executable is'+ Buffer)
else
WriteLn(SysErrorMessage(Res));
Readln;
结束。

您显示的方法可以工作,但 FindExecutable 更容易(更少的代码),并在XP及以上版本上运行。


We provide Flash tutorial videos that install on the local (Windows) hard disk with our application. Our app uses ShellExecute to open the html file (in whatever browser is associated with html files) in which they are embedded.

Apparently there's a bug in Chrome's more recent Flash players that fails to play local files (but files over the web are fine.)

(Frankly, I'm astonished that this bug hasn't been fixed by Google. Seems like a big one to me... but maybe not many people play Flash from locations other than the web?)

There's a work-around on the about:plugins screen in Chrome, but we can't ask our users to do that. Here's a discussion of the work-around: http://techsmith.custhelp.com/app/answers/detail/a_id/3518

I want to provide my users with an option to open our html files IE. If Chrome is their default browser, then I'd show a checkbox that says something embarrassing like "If our tutorial videos fail to play, check this box to try them in IE."

Is this XE2 code (from two years ago on SO: link) still reasonable?

if pos('CHROME', UpperCase(GetAssociation('C:\Path\File.html')) > 0 then
  // Chrome is the default browser

function GetAssociation(const DocFileName: string): string;
var
  FileClass: string;
  Reg: TRegistry;
begin
  Result := '';
  Reg := TRegistry.Create(KEY_EXECUTE);
  Reg.RootKey := HKEY_CLASSES_ROOT;
  FileClass := '';
  if Reg.OpenKeyReadOnly(ExtractFileExt(DocFileName)) then
  begin
    FileClass := Reg.ReadString('');
    Reg.CloseKey;
  end;
  if FileClass <> '' then begin
    if Reg.OpenKeyReadOnly(FileClass + '\Shell\Open\Command') then
    begin
      Result := Reg.ReadString('');
      Reg.CloseKey;
    end;
  end;
  Reg.Free;
end;

解决方案

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.

这篇关于将Chrome浏览器与Windows中的html文件相关联的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆