locked
How to change default homepage of IE,Firefox,Chrome and Opera programitically using C# application RRS feed

  • Question

  • User352005270 posted

    How to change default homepage of IE,Firefox,Chrome and Opera programitically using  C# application 

    Saturday, October 26, 2013 4:17 PM

All replies

  • User1759999623 posted

    This would only work if you installed the application on your client's computer.  Additionally, you would need to access the APIs for each individual browser through C#.  Note, however, you can use the setHomePage method in JavaScript to see it, but beware, as your users may not come back to your web app after this.

    Saturday, October 26, 2013 6:22 PM
  • User352005270 posted

    Please Tell me which kind of API I can use so that I can develop it batter .If you have more Idea then Please Share with me .

    Thank you

    Sunday, October 27, 2013 3:31 AM
  • User-742633084 posted

    Hi hemantkumar2...,

    For standard web application ( html + javascript) based, we cannot achieve the feature like programmatically change browser's default page (or other settings). If you do want to write some pure client/desktop application to programmtically change client-side browser's default page, you can consider use process monitor to check if the certain browser is using registry to store such setting. Then we can use code to programmtically read/write the registry value:

    #Process Monitor
    http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

    Sunday, October 27, 2013 11:44 PM
  • User352005270 posted

    I have find some code but its not sufficient .So I am asking to every one If there are perfect solution.

    For IE:

    RegistryKey startPageKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main", true);
    startPageKey.SetValue("Start Page", "http://stackoverflow.com");
    startPageKey.Close();

    For FireFox :

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

    For Chrome :

    http://stackoverflow.com/questions/4008194/how-can-i-programmatically-access-the-google-chrome-home-or-start-page

    But I need Perfect solution.Any body can help me.

    Monday, October 28, 2013 3:17 AM