titolo parla tutto.come faccio a cambiare il browser predefinito utilizzando C# o file batch
risposta
penso che sarà necessario modificare atleast due RegistryKeys e impostare il percorso per il browser alternativo:
HKEY_CLASSES_ROOT\http\shell\open\command
HKEY_CLASSES_ROOT\htmlfile\shell\open\command
Un alternative potrebbe essere quella di creare una voce aggiuntiva sotto la chiave Shell e impostarlo come l'azione di default :
[HKEY_CLASSES_ROOT\http\shell]
(default) set to OpenWithMyBrowser
[HKEY_CLASSES_ROOT\http\shell\OpenWithMyBrowser\command]
(default) set to "MyBrowser.exe"
Questo è stato molto utile grazie. –
Il browser predefinito viene salvato come voce nella chiave di registro di Windows. I valori vengono salvati su una base di protocollo come questo shell \ open \ command
HKEY_CLASSES_ROOT \ [protocollo] \
Dove protocollo può essere http, https, ecc su come accedere/modificare Registro di sistema i valori all'interno di C#, è possibile dare un'occhiata a this article
per i PC Windows 7 è necessario modificare la chiave di registro per
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\http
si può cambiare usando C#
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", true);
string browser = regkey.GetValue("Progid").ToString();
if (browser != "IE.HTTP")
{
regkey.SetValue("Progid", "IE.HTTP");
}
per prima vista os - (verificata in Windows XP)
RegistryKey regkey = Registry.ClassesRoot.OpenSubKey("http\\shell\\open\\command", true);
string browser = regkey.GetValue(null).ToString().ToLower().Replace("\"", "");
string defBrowser = "";
if (!browser.EndsWith("exe"))
{
//get rid of everything after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4);
defBrowser = browser.Substring(browser.LastIndexOf("\\") + 1);
}
if (defBrowser != "iexplore")
{
Process.Start("IExplore.exe");
ScreenScraperEngine.Instance.Wait(2000);
string iepath = "";
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName == "IEXPLORE")
{
iepath = p.MainModule.FileName;
}
}
if (iepath != "")
{
string iepathval = "\"" + iepath + "\" -nohome";
regkey.SetValue(null, iepathval);
}
}
Puoi aggiungere qualche dettaglio su * perché * si sta cercando di fare questo per dare un po 'di contesto ? – jerryjvl
Potrei usare un modo rapido per attivare il browser predefinito durante lo sviluppo. – Nifle
Perché dovrebbe fornire dettagli? La domanda è semplice. – msbg