本文介绍了如何使用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浏览器?
发布评论