zoukankan      html  css  js  c++  java
  • 读取和设置系统默认浏览器

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

    读取系统默认浏览器:

    Win7下:

    function GetDefExplorerPathOnWin7(): string;
    const
    CPath = '%sshellopencommand';

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

    oReg := TRegistry.Create();
    try
    oReg.RootKey := HKEY_CURRENT_USER;
    if oReg.OpenKeyReadOnly('SoftwareMicrosoftWindowsShellAssociationsUrlAssociationshttpUserChoice') 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('HTTPshellopencommand') 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('SoftwareMicrosoftWindowsShellAssociationsUrlAssociationshttpUserChoice', 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('HTTPshellopencommand', True) then
    begin
    sValue := Format('"%s" -- "%%1"', [ABrowserPath]);
    oReg.WriteString('', sValue);
    end;

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

  • 相关阅读:
    【javascript】ajax 基础
    【javascript】菜单滚动至顶部后固定
    【jquery】返回顶部效果
    【css】浅谈 inlineblock
    【jquery】checkbox——类似邮箱全选功能
    【javascript】返回顶部效果
    wcf基础知识之 查看soap消息 TcpTrace
    wcf系列之服务契约ServiceContract 之操作重载
    wcf 基础知识 之 消息交换模式 response/reply oneway deplex
    wcf基础知识之端口共享 portSharing
  • 原文地址:https://www.cnblogs.com/laoxia/p/7691353.html
Copyright © 2011-2022 走看看