首页 > 其他 > 详细

读取和设置系统默认浏览器

时间:2017-10-19 11:55:54      阅读:253      评论:0      收藏:0      [点我收藏+]

系统默认浏览器是保存在注册表中,读取和设置需要操作注册表,但是在xp和win7(Vista及以上系统)下的位置是不同的,需要分别读取和设置;

读取系统默认浏览器:

Win7下:

function GetDefExplorerPathOnWin7(): string;
const
CPath = ‘%s\shell\open\command‘;

var
oReg: TRegistry;
sKey, sPath: string;
begin
Result := ‘‘;
sKey := ‘‘;

oReg := TRegistry.Create();
try
oReg.RootKey := HKEY_CURRENT_USER;
if oReg.OpenKeyReadOnly(‘Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice‘) then
begin
sKey := Trim(oReg.ReadString(‘Progid‘));
end;

if not SameText(sKey, ‘‘) then
begin
oReg.CloseKey;

oReg.RootKey := HKEY_CLASSES_ROOT;
sPath := Format(CPath, [sKey]);
if oReg.OpenKeyReadOnly(sPath) then
begin
Result := Trim(oReg.ReadString(‘‘));
end;
end;
finally
oReg.CloseKey;
oReg.Free;
end;
end;

 

XP系统下:

function GetDefExplorerPathOnXP(): string;
var
oReg: TRegistry;
begin
Result := ‘‘;

oReg := TRegistry.Create();
try
oReg.RootKey := HKEY_CLASSES_ROOT;
if oReg.OpenKeyReadOnly(‘HTTP\shell\open\command‘) then
begin
Result := Trim(oReg.ReadString(‘‘));
end;
finally
oReg.CloseKey;
oReg.Free;
end;
end;

 

设置系统默认浏览器:

这里假设设置系统默认浏览器为IE,先将IE的路径读取到变量ABrowserPath中;

win7系统下:

procedure SetDefaultBrowerOnWin7();
var
oReg: TRegistry;
begin
oReg := TRegistry.Create();
try
oReg.RootKey := HKEY_CURRENT_USER;
if oReg.OpenKey(‘Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice‘, True) then
begin
oReg.WriteString(‘Progid‘, ‘IE.HTTP‘);
end;

oReg.CloseKey();
finally
oReg.Free;
end;
end;

 

XP系统下:

procedure SetDefaultBrowerOnXP(const ABrowserPath: string);
var
oReg: TRegistry;
sValue: string;
begin
oReg := TRegistry.Create();
try
oReg.RootKey := HKEY_CLASSES_ROOT;
if oReg.OpenKey(‘HTTP\shell\open\command‘, True) then
begin
sValue := Format(‘"%s" -- "%%1"‘, [ABrowserPath]);
oReg.WriteString(‘‘, sValue);
end;

oReg.CloseKey();
finally
oReg.Free;
end;
end;

读取和设置系统默认浏览器

原文:http://www.cnblogs.com/laoxia/p/7691353.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!