Win10强制设定默认浏览器

前些天有提到默认浏览器

但是这个工具是没用的。

也是解决文件类型关联程序的老哥提出的方法
https://kolbi.cz/blog/2019/01/27/register-a-portable-browser-and-make-it-the-default/

如文中所说,微软是有写方法的。

为什么传统的工具没用呢?简单说,就是因为每个浏览器的cli参数不同。

一个工具如果只要我指向firefox的程序,怎么可能知道profile的位置?你只有在注册表中自己指定。

上文中是直接使用reg,这里用ahk

新建一个var.ahk保存变量。

DefaultBrowserName(){
    return "FirefoxPortable"
}

DefaultBrowserDescription(){
    return "FirefoxPortable"
}   

DefaultBrowserPath(){
    return "D:\SCOOP\apps\firefox-portable\current\firefox.exe -profile ""D:\SCOOP\apps\firefox-portable\current\profile"""
}

再随便新建一个ahk。

#SingleInstance, Force
SendMode Input
SetWorkingDir, %A_ScriptDir%

#Include %A_ScriptDir%\var.ahk

name := DefaultBrowserName()
description := DefaultBrowserDescription()
path := DefaultBrowserPath()
exe := SubStrWordEnd(path, "exe")
args := GetArgs(path)
icon := exe . ",0"
progId := name . "HTM"
command := path

RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\RegisteredApplications, %name%, Software\Clients\StartMenuInternet\%name%\Capabilities
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%, , %description%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%\Capabilities, ApplicationDescription, %description%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%\Capabilities, ApplicationIcon, %icon%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%\Capabilities, ApplicationName, %description%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%\Capabilities\FileAssociations, .htm, %progId%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%\Capabilities\FileAssociations, .html, %progId%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%\Capabilities\Startmenu, StartMenuInternet, %name%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%\Capabilities\URLAssociations, http, %progId%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%\Capabilities\URLAssociations, https, %progId%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%\DefaultIcon, , %icon%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\%name%\shell\open\command, , "%exe%"
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Classes\%progId%, , %name% Handler
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Classes\%progId%, AppUserModelId, %name%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Classes\%progId%\Application, AppUserModelId, %name%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Classes\%progId%\Application, ApplicationIcon, %icon%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Classes\%progId%\Application, ApplicationName, %name%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Classes\%progId%\Application, ApplicationDescription, %description%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Classes\%progId%\Application, ApplicationCompany, %description%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Classes\%progId%\DefaultIcon, , %icon%
RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\Classes\%progId%\shell\open\command, , "%exe%" %args% "`%1"

SubStrWordEnd(path,str){
    return Trim(SubStr(path, 1, InStr(path, str) + Strlen(str)))
}

SubStrAfterWord(path,str){
    return Trim(SubStr(path, InStr(path, str) + Strlen(str)))
}

GetArgs(path){
    If (InStr(path, "firefox.exe")){
        args := SubStrAfterWord(path, "exe") . " -url"
    }
    Else
    {
        args := SubStrAfterWord(path, "exe")
    }
    return args
}

这里只解决了一个firefox,你需要按需修改GetArug。成功的话,应该就能看到图标。

测试不成功,var里只改了路径,但是运行后,注册表里所有该有exe的都是空的,能不能给个完整的注册表,想知道firefox.exe -profile这一条在注册表的位置

我分离参数肯定有问题。

我少了return