mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-05-24 14:19:48 +12:00
66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
|
using Microsoft.Win32;
|
|||
|
using System;
|
|||
|
|
|||
|
namespace SystemTrayMenu.Helper
|
|||
|
{
|
|||
|
public class FileUrl
|
|||
|
{
|
|||
|
private static string browserPath = string.Empty;
|
|||
|
public static string GetDefaultBrowserPath()
|
|||
|
{
|
|||
|
string urlAssociation = @"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http";
|
|||
|
string browserPathKey = @"$BROWSER$\shell\open\command";
|
|||
|
|
|||
|
RegistryKey userChoiceKey = null;
|
|||
|
string browserPath = FileUrl.browserPath;
|
|||
|
|
|||
|
if (string.IsNullOrEmpty(browserPath))
|
|||
|
{
|
|||
|
//Read default browser path from userChoiceLKey
|
|||
|
userChoiceKey = Registry.CurrentUser.OpenSubKey(urlAssociation + @"\UserChoice", false);
|
|||
|
|
|||
|
//If user choice was not found, try machine default
|
|||
|
if (userChoiceKey == null)
|
|||
|
{
|
|||
|
//Read default browser path from Win XP registry key
|
|||
|
var browserKey = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command", false);
|
|||
|
|
|||
|
//If browser path wasn’t found, try Win Vista (and newer) registry key
|
|||
|
if (browserKey == null)
|
|||
|
{
|
|||
|
browserKey =
|
|||
|
Registry.CurrentUser.OpenSubKey(
|
|||
|
urlAssociation, false);
|
|||
|
}
|
|||
|
var path = CleanifyBrowserPath(browserKey.GetValue(null) as string);
|
|||
|
browserKey.Close();
|
|||
|
return path;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
// user defined browser choice was found
|
|||
|
string progId = (userChoiceKey.GetValue("ProgId").ToString());
|
|||
|
userChoiceKey.Close();
|
|||
|
|
|||
|
// now look up the path of the executable
|
|||
|
string concreteBrowserKey = browserPathKey.Replace("$BROWSER$", progId);
|
|||
|
var kp = Registry.ClassesRoot.OpenSubKey(concreteBrowserKey, false);
|
|||
|
browserPath = CleanifyBrowserPath(kp.GetValue(null) as string);
|
|||
|
kp.Close();
|
|||
|
}
|
|||
|
|
|||
|
FileUrl.browserPath = browserPath;
|
|||
|
}
|
|||
|
|
|||
|
return browserPath;
|
|||
|
}
|
|||
|
|
|||
|
private static string CleanifyBrowserPath(string p)
|
|||
|
{
|
|||
|
string[] url = p.Split('"');
|
|||
|
string clean = url[1];
|
|||
|
return clean;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|