Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用C#在Internet Explorer中更改主页?_C# - Fatal编程技术网

如何使用C#在Internet Explorer中更改主页?

如何使用C#在Internet Explorer中更改主页?,c#,C#,是否可以在C#应用程序中更改Internet Explorer的主页?其他浏览器(Firefox、Chrome)的解决方案也不错。是的,你可以。主页存储在注册表中。只要您的C#程序有权修改注册表,您就应该能够将此项更改为您想要的任何页面 即 火狐 Firefox不会将主页存储在注册表中,因为它具有 $APPDATA\Mozilla\Firefox\profiles[profile]下的不同配置文件 name]需要读取的文件是prefs.js,行: 用户首选(“浏览器.启动.主页”,…) 要获

是否可以在C#应用程序中更改Internet Explorer的主页?其他浏览器(Firefox、Chrome)的解决方案也不错。

是的,你可以。主页存储在注册表中。只要您的C#程序有权修改注册表,您就应该能够将此项更改为您想要的任何页面

火狐 Firefox不会将主页存储在注册表中,因为它具有 $APPDATA\Mozilla\Firefox\profiles[profile]下的不同配置文件 name]需要读取的文件是prefs.js,行: 用户首选(“浏览器.启动.主页”,…)

要获取默认配置文件,您需要阅读 $APPDATA\Mozilla\Firefox\profiles.ini。你得绕过去 每个[配置文件#],直到默认值=1,您的配置文件名将从 路径=

如果你想让我把它变成一个函数(听起来是个好主意) 也可以)或者如果你想做的话,在维基上发布

-斯图

来自专家交换的未经测试的代码

public static void SetMozilla(string strURL)
        {
            try
            {
                string strSystemUname = Environment.UserName.ToString().Trim();
                string systemDrive = Environment.ExpandEnvironmentVariables("%SystemDrive%");
                string strDirectory = "";
                string strPrefFolder = "";
                if (Directory.Exists(systemDrive + "\\Documents and Settings\\" + strSystemUname + "\\Application Data\\Mozilla\\Firefox\\Profiles"))
                {
                    strDirectory = systemDrive + "\\Documents and Settings\\" + strSystemUname + "\\Application Data\\Mozilla\\Firefox\\Profiles";
                }
                else if (Directory.Exists(systemDrive + "\\WINDOWS\\Application Data\\Mozilla\\Firefox\\Profiles"))
                {
                    strDirectory = systemDrive + "\\WINDOWS\\Application Data\\Mozilla\\Firefox\\Profiles";
                }
                if (strDirectory.Trim().Length != 0)
                {
                    System.IO.DirectoryInfo oDir = new DirectoryInfo(strDirectory);
                    //System.IO.DirectoryInfo[] oSubDir;
                    //oSubDir = oDir.GetDirectories(strDirectory);
                    foreach (DirectoryInfo oFolder in oDir.GetDirectories())
                    {
                        if (oFolder.FullName.IndexOf(".default") >= 0)
                        {
                            strPrefFolder = oFolder.FullName;
                            CreatePrefs(strURL, strPrefFolder);
                        }
                    }

                }
            }
            catch
            { }
        }
        private static void CreatePrefs(string strURL, string strFolder)
        {
            StringBuilder sbPrefs = new StringBuilder();
            sbPrefs.Append("# Mozilla User Preferences\n\r");
            sbPrefs.Append("/* Do not edit this file.\n\r*\n\r"); 
            sbPrefs.Append("* If you make changes to this file while the application is running,\n\r");
            sbPrefs.Append("* the changes will be overwritten when the application exits.,\n\r*\n\r"); 
            sbPrefs.Append("* To make a manual change to preferences, you can visit the URL about:config\n\r");
            sbPrefs.Append("* For more information, see http://www.mozilla.org/unix/customizing.html#prefs\n\r");
            sbPrefs.Append("*/\n\r");
            sbPrefs.Append("user_pref(\"app.update.lastUpdateTime.addon-background-update-timer\", 1188927425);\n\r");
            sbPrefs.Append("user_pref(\"app.update.lastUpdateTime.background-update-timer\", 1188927425);\n\r");
            sbPrefs.Append("user_pref(\"app.update.lastUpdateTime.blocklist-background-update-timer\", 1188927425);\n\r");
            sbPrefs.Append("user_pref(\"app.update.lastUpdateTime.search-engine-update-timer\", 1188927425);\n\r");
            sbPrefs.Append("user_pref(\"browser.anchor_color\", \"#0000FF\");\n\r");
            sbPrefs.Append("user_pref(\"browser.display.background_color\", \"#C0C0C0\");\n\r");
            sbPrefs.Append("user_pref(\"browser.display.use_system_colors\", true);\n\r");
            sbPrefs.Append("user_pref(\"browser.formfill.enable\", false);\n\r");
            sbPrefs.Append("user_pref(\"browser.history_expire_days\", 20);\n\r");
            sbPrefs.Append("user_pref(\"browser.shell.checkDefaultBrowser\", false);\n\r");
            sbPrefs.Append("user_pref(\"browser.startup.homepage\", \"" + strURL +"\");\n\r");
            sbPrefs.Append("user_pref(\"browser.startup.homepage_override.mstone\", \"rv:1.8.1.6\");\n\r");
            sbPrefs.Append("user_pref(\"browser.visited_color\", \"#800080\");\n\r");
            sbPrefs.Append("user_pref(\"extensions.lastAppVersion\", \"2.0.0.6\");\n\r");
            sbPrefs.Append("user_pref(\"intl.charsetmenu.browser.cache\", \"UTF-8, ISO-8859-1\");\n\r");
            sbPrefs.Append("user_pref(\"network.cookie.prefsMigrated\", true);\n\r");
            sbPrefs.Append("user_pref(\"security.warn_entering_secure\", false);\n\r");
            sbPrefs.Append("user_pref(\"security.warn_leaving_secure\", false);\n\r");
            sbPrefs.Append("user_pref(\"security.warn_submit_insecure\", false);\n\r");
            sbPrefs.Append("user_pref(\"security.warn_submit_insecure.show_once\", false);\n\r");
            sbPrefs.Append("user_pref(\"spellchecker.dictionary\", \"en-US\");\n\r");
            sbPrefs.Append("user_pref(\"urlclassifier.tableversion.goog-black-enchash\", \"1.32944\");\n\r");
            sbPrefs.Append("user_pref(\"urlclassifier.tableversion.goog-black-url\", \"1.14053\");\n\r");
            sbPrefs.Append("user_pref(\"urlclassifier.tableversion.goog-white-domain\", \"1.23\");\n\r");
            sbPrefs.Append("user_pref(\"urlclassifier.tableversion.goog-white-url\", \"1.371\");\n\r");
            StreamWriter writer = new StreamWriter(strFolder + "\\prefs.js");
            writer.Write(sbPrefs.ToString()); 
            writer.Close();
            writer.Dispose();
            GC.Collect();
        }

其他来源


    • 对于IE,您必须设置注册表项:

      HKCU\Software\Microsoft\Internet Explorer\Main\Start Page
      
      对于firefox,您需要编辑js文件:
      prefs.js
      。 这可以在以下位置找到:
      C:\Users\[USERNAME]\AppData\Roaming\Mozilla\Firefox\Profiles\[User Subfolder]

      Chrome,将it数据存储在:
      C:\Users\\AppData\Local\chromius\User Data\Default
      文件夹,位于
      首选项
      文件中。
      这是JSON格式的。编辑它应该不会有问题

      Internet Explorer的主页位于
      HKEY\U CURRENT\U USER\Software\Microsoft\Internet Explorer\Main
      (根据)的
      起始页
      注册表项中,因此您可以使用
      Microsoft.Win32
      中的
      注册表类设置它(根据):


      我恐怕不知道其他的。

      即:编辑注册表项HKEY\U CURRENT\U USER\Software\Microsoft\Internet Explorer\Main\Start Page

      Firefox:find(需要解析文件)

      Chrome:在首选项文件中找到默认的“主页”设置:
      C:\Users\%USERNAME%/AppData\AppData\Local\Google\Chrome\User Data\default


      对于注册表,请使用.NET类。对于文件,您需要解析文件并对其进行修改。

      除上述答案外,如果有集团策略,您可能还需要检查以下内容:
      HKCU\Software\Policys\Microsoft\Internet Explorer\Main\Start Page

      可能重复,谢谢!这正是我所需要的。
      HKCU\Software\Microsoft\Internet Explorer\Main\Start Page
      
      RegistryKey startPageKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main", true);
      startPageKey.SetValue("Start Page", "http://stackoverflow.com");
      startPageKey.Close();