如何使用C#找到默认Web浏览器?

编程入门 行业动态 更新时间:2024-10-24 09:29:55
本文介绍了如何使用C#找到默认Web浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有一种方法,我可以找出使用C#我的默认网页浏览器的名字吗?(火狐,谷歌Chrome等)

Is there a way I can find out the name of my default web browser using C#? (Firefox, Google Chrome, etc..)

能否请您用一个例子告诉我?

Can you please show me with an example?

推荐答案

您可以看看here为一个例子,但主要是它可以这样做:

You can look here for an example, but mainly it can be done like this:

internal string GetSystemDefaultBrowser() { string name = string.Empty; RegistryKey regKey = null; try { //set the registry key we want to open regKey = Registry.ClassesRoot.OpenSubKey("HTTP\\shell\\open\\command", false); //get rid of the enclosing quotes name = regKey.GetValue(null).ToString().ToLower().Replace("" + (char)34, ""); //check to see if the value ends with .exe (this way we can remove any command line arguments) if (!name.EndsWith("exe")) //get rid of all command line arguments (anything after the .exe must go) name = name.Substring(0, name.LastIndexOf(".exe") + 4); } catch (Exception ex) { name = string.Format("ERROR: An exception of type: {0} occurred in method: {1} in the following module: {2}", ex.GetType(), ex.TargetSite, this.GetType()); } finally { //check and see if the key is still open, if so //then close it if (regKey != null) regKey.Close(); } //return the value return name; }

更多推荐

如何使用C#找到默认Web浏览器?

本文发布于:2023-10-11 22:34:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483035.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   浏览器   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!