繁体   English   中英

在默认浏览器 (C#) Windows10 的列表中显示自己的应用程序

[英]Show own app in list for default browser (C#) Windows10

我希望我的应用程序显示在默认浏览器下。 在过去的 3 天里,我发现了很多关于此的文章。 似乎没有解决方案是正确的。 它应该出现在这里:在此处输入图像描述

它应该适用于 Windows 10。在文章( https://docs.microsoft.com/en-us/windows/win32/shell/default-programs?redirectedfrom=MSDN )中显示了哪些注册表项应该处理这个问题。 但它不起作用。 是的,我已经阅读了有关更改 win 10 中标准应用程序设置方式的警报,但我不想以编程方式设置它,我希望我的应用程序显示在那里。 有人对我有更具体的信息吗?

我的代码设置了文章中的注册表项,在注册表中,我可以在使用我的应用程序后看到它们。 所以我不会在这里显示我添加注册表项的代码,但是当然,有没有解决方案,我会添加代码......

谢谢!

又是我。 我终于找到了解决方案。 请原谅我的这段代码,但我没有找到注册表项的“官方”文档。 我确定我的代码中有一些不需要的键,但它可以工作,因此您可以自己测试哪些键可以省略。 该代码是搜索 www 约 7 天的结果

        public static void SetDefaultBrowser(string _appName, string _appPath, string _appID, string _appDescription)
    {

        string pfadschluessel = "SOFTWARE\\Clients\\StartMenuInternet\\" + _appName;
        string pfadschluessel_cap = pfadschluessel + "\\Capabilities";
        string pfadschluessel_cap_fileA = pfadschluessel_cap + "\\FileAssociations";
        string pfadschluessel_cap_Startmenu = pfadschluessel_cap + "\\Startmenu";
        string pfadschluessel_cap_URL = pfadschluessel_cap + "\\URLAssociations";
        Registry.LocalMachine.CreateSubKey(pfadschluessel).SetValue("", _appName);
        Registry.LocalMachine.CreateSubKey(pfadschluessel).SetValue("LocalizedString", "@" + _appPath);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap).SetValue("ApplicationDescription", _appDescription);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap).SetValue("ApplicationIcon", _appPath + ",0");
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap).SetValue("ApplicationName", _appName);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_fileA).SetValue(".htm", _appID);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_fileA).SetValue(".html", _appID);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_fileA).SetValue(".shtml", _appID);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_fileA).SetValue(".xhtml", _appID);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_fileA).SetValue(".xht", _appID);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_Startmenu).SetValue("StartMenuInternet", _appName);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_URL).SetValue("ftp", _appID);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_URL).SetValue("http", _appID);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_URL).SetValue("https", _appID);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_URL).SetValue("mailto", _appID);
        Registry.LocalMachine.CreateSubKey(pfadschluessel_cap_URL).SetValue("webcal", _appID);
        Registry.LocalMachine.CreateSubKey(pfadschluessel + "\\DefaultIcon").SetValue("", _appPath + ",0");
        Registry.LocalMachine.CreateSubKey(pfadschluessel + "\\InstallInfo").SetValue("", "");
        Registry.LocalMachine.CreateSubKey(pfadschluessel + "\\shell\\open\\command").SetValue("", "\"" + _appPath + "\"");
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\Classes\\.htm\\OpenWithProgIds").SetValue(_appID, "");
        string PFAD_software_ = "SOFTWARE\\" + _appName;
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities").SetValue("ApplicationDescription", _appDescription);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities").SetValue("ApplicationName", _appID);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities").SetValue("ApplicationIcon", _appPath);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities\\FileAssociations").SetValue(".htm", _appID);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities\\FileAssociations").SetValue(".html", _appID);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities\\FileAssociations").SetValue(".shtml", _appID);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities\\FileAssociations").SetValue(".xhtml", _appID);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities\\FileAssociations").SetValue(".xht", _appID);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities\\Startmenu").SetValue("StartmenuInternet", _appPath);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities\\UrlAssociations").SetValue("ftp", _appID);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities\\UrlAssociations").SetValue("http", _appID);
        Registry.LocalMachine.CreateSubKey(PFAD_software_ + "\\Capabilities\\UrlAssociations").SetValue("https", _appID);
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\RegisteredApplications").SetValue(_appName, PFAD_software_ + "\\Capabilities");
        Registry.CurrentUser.CreateSubKey("SOFTWARE\\RegisteredApplications").SetValue(_appName, PFAD_software_ + "\\Capabilities");
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\Classes\\" + _appID).SetValue("FriendlyTypeName", _appName);
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\Classes\\" + _appID).SetValue("Editflags", 2);
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\Classes\\" + _appID + "\\DefaultIcon").SetValue("", _appPath + ",0");
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\Classes\\" + _appID + "\\shell\\open\\command").SetValue("", "\"" + _appPath + "\"%1");
        Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" + _appName + ".exe").SetValue("Path", _appPath);
        Registry.ClassesRoot.CreateSubKey(_appID + "\\DefaultIcon").SetValue("", _appPath + ",0");
        Registry.ClassesRoot.CreateSubKey(_appID + "\\shell\\open\\command").SetValue("", "\"" + _appPath + "\"%1");
        Registry.ClassesRoot.CreateSubKey(_appID).SetValue("AppUserModelId", _appName);
        Registry.ClassesRoot.CreateSubKey(_appID + "\\Application").SetValue("ApplicationDescription", _appDescription);
        Registry.ClassesRoot.CreateSubKey(_appID + "\\Application").SetValue("ApplicationName", _appName);
        Registry.ClassesRoot.CreateSubKey(_appID + "\\Application").SetValue("ApplicationIcon", _appPath);
        Registry.LocalMachine.CreateSubKey(pfadschluessel + "\\DefaultIcon").SetValue("", _appPath + ",0");
        Registry.LocalMachine.CreateSubKey(pfadschluessel + "\\shell\\open\\command").SetValue("", _appPath);
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\RegisteredApplications").SetValue(_appName, pfadschluessel_cap);
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\Classes\\" + _appID).SetValue("FriendlyTypeName", _appName);
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\Classes\\" + _appID).SetValue("Editflags", 2);
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\Classes\\" + _appID + "\\DefaultIcon").SetValue("", _appPath + ",0");
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\Classes\\" + _appID + "\\shell\\open\\command").SetValue("", "\"" + _appPath + "\"%1");
        Registry.LocalMachine.CreateSubKey("SOFTWARE\\MDK\\" + _appID + "\\Capabilities").SetValue("ApplicationName", _appName);
    }

_appName = 您的浏览器名称,例如 FooBar Browser

_appPath = .exe 的路径,例如 C:\foobar\foobar.exe

_appID = 软件的appID。 如果您编写了一个新的控制台应用程序(classname = Program, Projectname = foobar),那么它将是“foobar.Program”

_appDescription = 简短描述,它是什么

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM