¿De qué RegKey se puede obtener la ruta predeterminada de la aplicación del navegador?Windows RegKey - Ruta de la aplicación del navegador predeterminado
¿La mejor manera de llegar desde C# /. NET?
¿De qué RegKey se puede obtener la ruta predeterminada de la aplicación del navegador?Windows RegKey - Ruta de la aplicación del navegador predeterminado
¿La mejor manera de llegar desde C# /. NET?
Aquí está la clave que desea:
HKEY_LOCAL_MACHINE \ SOFTWARE \ Classes \ http \ shell \ open \ command
Y he aquí una rápida registry tutorial for C#, si lo necesita.
Editar:
Para configuración por usuario, utilice esta clave:
HKEY_CLASSES_ROOT \ http \ shell \ open \ command
(HKCR tiene la máquina y el usuario configuración, el usuario tiene prioridad).
Tenga en cuenta que esto podría no funcionar en Vista. Para más información, see here.
para las ventanas ruta del explorador 7 predeterminada para guardar en Registro siguiente clave
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\http
mediante el uso de C# se puede obtener de la siguiente manera -
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", false);
string browser = regkey.GetValue("Progid").ToString();
Con base en sus respuestas que escribió el código de ejemplo que debe haz lo que quieras (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;
}
En Win7, ese "Progid" no parece contener ningún enlace. Contiene un ID de programa que se buscará en el registro en "HKCR/FetchedProgramId" (con FetchedProgramId el valor de identificación del programa recuperado anteriormente). Debajo de esa tecla está, de nuevo, un "comando \ shell \ open \", en el que se encuentra la ruta real. – Nyerguds
Esto no parece dar la ruta en Windows 10. Solo devolvió un valor de IE.HTTP – Fractal
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));
}
No debe sondear el registro para intentar iniciar el navegador web predeterminado. ¿Que estás tratando de hacer? – Michael
No quería iniciar el navegador predeterminado. Tenía un programa que podía tomar decisiones diferentes en función de la preferencia de alguien en el navegador. – BuddyJoe