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


    系统默认浏览器是保存在注册表中,读取和设置需要操作注册表,但是在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;

  • 相关阅读:
    MT4 图表上设置字符
    MC- 交易并设置止损
    MC- 挂单STOP交易
    MC-设置 止盈
    MC 跨周期 画线
    美版MC 使用
    改变和恢复view的方向
    app被Rejected 的各种原因翻译。这个绝对有用。
    更改navigationController push和pop界面切换动画
    线程访问外部数据
  • 原文地址:https://www.cnblogs.com/laoxia/p/7691353.html
Copyright © 2020-2023  润新知