下面的代码应该检测IE,但是它给Crome提供了错误的输出。
为什么此代码在Win7 + Chrome中不起作用;如何检测IE不是默认的?
if pos('iexplore.exe',lowercase(CheckBrowser(nil))) >0 then say "yes its IEE!!"
function CheckBrowser(Sender: TObject) : ansistring;
var
Reg: TRegistry;
KeyName: string;
ValueStr: string;
begin
result := '';
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CLASSES_ROOT;
KeyName := 'htmlfile\shell\open\command';
if Reg.OpenKey(KeyName, False) then
begin
ValueStr := Reg.ReadString('');
Reg.CloseKey;
result := ValueStr;
end
else
finally
Reg.Free;
end;
end;
答案 0 :(得分:3)
你在找错了地方。要检查的地方是:
HKEY_CLASSES_ROOT\http\shell\open\command
阅读以下博客了解更多详情:
答案 1 :(得分:1)
我的电脑我把IExplore设为默认值。
默认= IExplore
HKEY_CLASSES_ROOT \ http \ shell \ open \ command
“C:\ Program Files(x86)\ Google \ Chrome \ Application \ chrome.exe” - “%1”
HKEY_CLASSES_ROOT \ htmlfile \ shell \ open \ command
“C:\ Program Files \ Internet Explorer \ IEXPLORE.EXE”%1
将默认浏览器更改为chrome
默认= Chrome
HKEY_CLASSES_ROOT \ http \ shell \ open \ command
“C:\ Program Files(x86)\ Google \ Chrome \ Application \ chrome.exe” - “%1”
HKEY_CLASSES_ROOT \ htmlfile \ shell \ open \ command
“C:\ Program Files \ Internet Explorer \ IEXPLORE.EXE”%1
\ htmlfile \ shell \ open \ command 或 http \ shell \ open \ command 在HKEY_CLASSES_ROOT中不起作用
我必须创建一个html文件,然后找到可执行文件
function GetDefaultBrowser(): String;
var
TempPath: String;
FileHandle: THandle;
Buffer: array[0..MAX_PATH] of Char;
begin
Result := '';
TempPath := System.IOUtils.TPath.GetTempPath;
FileHandle := System.SysUtils.FileCreate(TempPath + 'htmpl.htm');
if FileHandle <> INVALID_HANDLE_VALUE then
begin
FillChar(Buffer, Length(Buffer), #0);
if FindExecutable('htmpl.htm', PChar(TempPath), Buffer) > 32 then
begin
Result := Buffer;
end;
System.SysUtils.FileClose(FileHandle);
System.SysUtils.DeleteFile(TempPath + 'htmpl.htm');
end;
end;