none
Set IE Home page

    Question

  • Using a windows 7 machine and I want to set IE home page. I'm getting a null value in the reg
     when I step through it currently. Do I have the right path?
    public static void Defualt_AHA_IE_HomePage()
            {
                try
                {
                    RegistryKey myKey = Registry.LocalMachine.OpenSubKey("HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\Main", true);
                    if (myKey != null)
                    {
                        myKey.SetValue("Start Page", "http://www.aha.org/", RegistryValueKind.String);
                        myKey.Close();
                    }
                }
                catch(Exception ex)
                {
    
                }            
            }

    • Edited by old_School Tuesday, April 4, 2017 5:56 PM
    Tuesday, April 4, 2017 5:55 PM

Answers

  • Hi old_School,

    Please look into below code. Local machine change is not accessible due to security issue. Please use "CurrentUser" property to access the registry value. Also you were passing the registry path wrong. By using CurrentUser property it automatically detects "HKEY_CURRENT_USER" location. So you just need to pass the sub directory location. Hope this helps you.

    RegistryKey myKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Main", true);
                if (myKey != null)
                {
                    myKey.SetValue("Start Page", "http://www.aha.org/", RegistryValueKind.String);
                    myKey.Close();
                }


    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Tuesday, April 4, 2017 7:27 PM
    Moderator

All replies

  • Hi old_School,

    Please look into below code. Local machine change is not accessible due to security issue. Please use "CurrentUser" property to access the registry value. Also you were passing the registry path wrong. By using CurrentUser property it automatically detects "HKEY_CURRENT_USER" location. So you just need to pass the sub directory location. Hope this helps you.

    RegistryKey myKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Main", true);
                if (myKey != null)
                {
                    myKey.SetValue("Start Page", "http://www.aha.org/", RegistryValueKind.String);
                    myKey.Close();
                }


    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Tuesday, April 4, 2017 7:27 PM
    Moderator
  • Well no error but it did not reset the home page hmm

    public static void Defualt_AHA_IE_HomePage()
            {
                try
                {
                    RegistryKey myKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Main", true);
                    if (myKey != null)
                    {
                        myKey.SetValue("Start Page", "http://www.aha.org/", RegistryValueKind.String);
                        myKey.Close();
                    }
                }
                catch(Exception ex)
                {
    
                }            
            }

    Am I doing this correctly?

    • Marked as answer by old_School Tuesday, April 4, 2017 8:33 PM
    • Unmarked as answer by old_School Tuesday, April 4, 2017 8:33 PM
    Tuesday, April 4, 2017 7:57 PM
  • It is working for me. What value do you have under "Current User" setting?

    registry


    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Tuesday, April 4, 2017 8:08 PM
    Moderator
  • Weird I don't have a start page listed

    Tuesday, April 4, 2017 8:30 PM
  • Oh I see they have it locked down on this machine. I'm at work so that makes sense. Seems to be working though. Thank you
    Tuesday, April 4, 2017 8:33 PM