Wednesday, October 13, 2010

Readout / Change Home Page of the Internet Explorer

The start page of the Internet Explorer is saved in the registry in the key HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Start Page.
This information can now be readout via C# and changed at will. A little registry tutorial is available on this blog.
Therefore, the functions used here should be known and I will just post the source code:
First a function, which determines the home page of the Internet Explorer and returns it as a string:

private string GetIEStartPage()
{
    RegistryKey StartPageKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main"); // open the right registry path
    return StartPageKey.GetValue("Start Page").ToString(); // readout the value of the"Start Page" and return it
}

Now to the function for change the start page, this expects the new home page as parameter:

private void SetIEStartPage(string newStartPage)
{
    RegistryKey StartPageKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main"true); // open the right path in the registry with writing rights
    StartPageKey.SetValue("Start Page", newStartPage); // write the new value in the key"Start Page"
}

No comments:

Post a Comment