Da quale RegKey è possibile ottenere il percorso dell'applicazione browser predefinito?RegKey di Windows - Percorso applicazione browser predefinito
Il modo migliore per arrivare da C# /. NET?
Da quale RegKey è possibile ottenere il percorso dell'applicazione browser predefinito?RegKey di Windows - Percorso applicazione browser predefinito
Il modo migliore per arrivare da C# /. NET?
Ecco la chiave che si desidera:
HKEY_LOCAL_MACHINE \ SOFTWARE \ Classes \ http open \ command shell \ \
Ed ecco una rapida registry tutorial for C#, se ne avete bisogno.
Edit:
Per le impostazioni per utente, utilizzare questa chiave:
HKEY_CLASSES_ROOT \ http comando \ open shell \ \
(HKCR ha sia la macchina e l'utente impostazioni, l'utente ha priorità).
Si noti che questo potrebbe non funzionare su Vista. Per maggiori informazioni, see here.
per le finestre percorso del browser 7 di salvataggio predefinito nella seguente chiave di registro
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\http
utilizzando C# si può ottenere come segue -
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", false);
string browser = regkey.GetValue("Progid").ToString();
In base alle vostre risposte ho scritto questo codice di esempio che dovrebbe fai quello che vuoi (non testato)
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;
}
Su Win7, comunque, "Progid" non sembra contenere link. Contiene un ID programma da cercare nel registro sotto "HKCR/FetchedProgramId" (con FetchedProgramId l'ID del programma recuperato prima). Sotto quella chiave c'è, ancora, un "comando \ shell \ apri \", in cui trovi il percorso attuale. – Nyerguds
Questo non sembra dare il percorso su Windows 10. Ha restituito solo un valore di IE.HTTP – Fractal
Ho appena creato una funzione per questo:
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));
}
Non cercare il Registro di sistema per tentare di avviare il browser Web predefinito. Cosa stai cercando di fare? – Michael
Non volevo avviare il browser predefinito. Avevo un programma in grado di fare alcune scelte diverse sulla base di quale fosse la preferenza di un browser. – BuddyJoe