Windows RegKey - Ruta predeterminada de la aplicación del navegador
Pregunta
¿De qué RegKey puede obtener la ruta de la aplicación de navegador predeterminada?
¿La mejor manera de acceder desde C # / .NET?
Solución
Aquí está la clave que deseas:
HKEY_LOCAL_MACHINE \ SOFTWARE \ Classes \ http \ shell \ open \ command
Y aquí hay un rápido tutorial de registro para C # , si lo necesita.
Editar :
Para la configuración por usuario, use esta clave:
HKEY_CLASSES_ROOT \ http \ shell \ open \ command
(HKCR tiene configuraciones de máquina y usuario, el usuario tiene prioridad).
Tenga en cuenta que esto podría no funcionar en Vista . Para obtener más información, vea aquí .
Otros consejos
para la ruta del navegador predeterminada de Windows 7, guárdela en la siguiente clave de registro
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\http
utilizando c # puede obtenerlo de la siguiente manera:
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", false);
string browser = regkey.GetValue("Progid").ToString();
Basándome en sus respuestas, escribí este código de ejemplo que debería hacer lo que quiere (no probado)
public static string GetDefaultBrowserPath()
{
string defaultBrowserPath = null;
RegistryKey regkey;
// Check if we are on Vista or Higher
OperatingSystem OS = Environment.OSVersion;
if ((OS.Platform == PlatformID.Win32NT) && (OS.Version.Major >= 6))
{
regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", false);
if (regkey != null)
{
defaultBrowserPath = regkey.GetValue("Progid").ToString();
}
else
{
regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes\\IE.HTTP\\shell\\open\\command", false);
defaultBrowserPath = regkey.GetValue("").ToString();
}
}
else
{
regkey = Registry.ClassesRoot.OpenSubKey("http\\shell\\open\\command", false);
defaultBrowserPath = regkey.GetValue("").ToString();
}
return defaultBrowserPath;
}
Acabo de hacer una función para esto:
public void launchBrowser(string url)
{
string browserName = "iexplore.exe";
using (RegistryKey userChoiceKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"))
{
if (userChoiceKey != null)
{
object progIdValue = userChoiceKey.GetValue("Progid");
if (progIdValue != null)
{
if(progIdValue.ToString().ToLower().Contains("chrome"))
browserName = "chrome.exe";
else if(progIdValue.ToString().ToLower().Contains("firefox"))
browserName = "firefox.exe";
else if (progIdValue.ToString().ToLower().Contains("safari"))
browserName = "safari.exe";
else if (progIdValue.ToString().ToLower().Contains("opera"))
browserName = "opera.exe";
}
}
}
Process.Start(new ProcessStartInfo(browserName, url));
}