Delphi 获取浏览器路径 注册表获取默认浏览器、注册表读取IE路径 拼接IE路径。能想到的挫招都用上了。
function GetBrowserPath:string;
var
hMyKey : HKEY;
sPath : array [0..Max_Path-1] of char;
sBrowserPath: string;
sTemp : string;
vType, dLength: DWORD;
begin
dLength := SizeOf(sPath);
vType := REG_SZ;
if RegOpenKeyEx(HKEY_CLASSES_ROOT,
'http\shell\open\command',
0,
KEY_READ,hMyKey) = ERROR_SUCCESS then
begin
if RegQueryValueEx(hMyKey,'',nil, @vType, @sPath[0], @dLength)= ERROR_SUCCESS then
begin
sBrowserPath := sPath;
sBrowserPath := Copy(sBrowserPath, Pos('"', sBrowserPath) + 1, Length(sBrowserPath));
sBrowserPath := Copy(sBrowserPath, 1, Pos('"', sBrowserPath) - 1) ;
end;
end;
if sBrowserPath ='' then
begin
if RegOpenKeyEx(HKEY_LOCAL_MACHINE,
'Software\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE',
0,
KEY_READ,
hMyKey)=ERROR_SUCCESS then
begin
if RegQueryValueEx(hMyKey, '' , nil, @vType, @sPath[0], @dLength) = 0 then
begin
sBrowserPath := sPath;
end;
end;
end;
if sBrowserPath ='' then
begin
GetSystemDirectory(sPath, SizeOf(sPath));
sTemp := string(sPath) + '\';
Delete(sTemp, Pos(':',sTemp) + 1, Length(sTemp));
sTemp := Copy(sTemp,0,Pos(':',sTemp));
sBrowserPath := sTemp + '\Program Files\Internet Explorer\IEXPLORE.EXE';
end;
Result := sBrowserPath;
RegCloseKey(hMyKey);
end;