Browser 如何使用c#或批处理文件更改默认浏览器
标题说明了一切。我认为您至少需要修改两个,并设置替代浏览器的路径:Browser 如何使用c#或批处理文件更改默认浏览器,browser,default,Browser,Default,标题说明了一切。我认为您至少需要修改两个,并设置替代浏览器的路径: HKEY_CLASSES_ROOT\http\shell\open\command HKEY_CLASSES_ROOT\htmlfile\shell\open\command 可能需要在Shell键下创建一个附加项,并将其设置为默认操作: [HKEY_CLASSES_ROOT\http\shell] (default) set to OpenWithMyBrowser [HKEY_CLASSES_ROOT\http\shel
HKEY_CLASSES_ROOT\http\shell\open\command
HKEY_CLASSES_ROOT\htmlfile\shell\open\command
可能需要在Shell键下创建一个附加项,并将其设置为默认操作:
[HKEY_CLASSES_ROOT\http\shell]
(default) set to OpenWithMyBrowser
[HKEY_CLASSES_ROOT\http\shell\OpenWithMyBrowser\command]
(default) set to "MyBrowser.exe"
默认浏览器保存为windows注册表项中的一个条目。这些值是基于协议保存的,如下所示 HKEY\U CLASSES\U ROOT\[协议]\shell\open\command
协议可以是http、https等。关于如何访问/修改C#中的注册表值,您可以查看windows 7 pc的,您需要更改
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\http
你可以用c#改变这一点
对于vista操作系统之前的版本-(已在windows XP中签入)
你可以添加一些关于为什么要这样做的细节来提供一些上下文吗?我可以用一种快速的方法在开发时切换默认浏览器。为什么他需要提供细节?问题很简单。
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");
}
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);
}
}