2009-05-01 12 views
7

¿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?

+3

No debe sondear el registro para intentar iniciar el navegador web predeterminado. ¿Que estás tratando de hacer? – Michael

+0

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

Respuesta

16

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.

+0

Pero supongo que te refieres a HKEY_CURRENT_USER ¿verdad? – BuddyJoe

+0

No hay una clave coincidente en HKCU. Ver mi edición para más información. –

+0

impresionante. Gracias. – BuddyJoe

1

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(); 
1

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; 
    } 
+2

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

+0

Esto no parece dar la ruta en Windows 10. Solo devolvió un valor de IE.HTTP – Fractal

0

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)); 
    } 
Cuestiones relacionadas