Results 1 to 4 of 4

Thread: Registry Reading

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    59

    Registry Reading

    Keep getting an error on this code:

    Code:
                RegistryKey rKey = Registry.LocalMachine;
                rKey.OpenSubKey(@"\SOFTWARE\Blizzard Entertainment\World of Warcraft", true);
                try
                {
                    return rKey.GetValue("InstallPath").ToString();
                }
                catch (NullReferenceException)
                {
                    return null;
                }
    I KNOW for certain that a key exists in this location, so the key not existing is out of the question.

    Unsure what the issue could be.

    ETA: Obviously the error no longer appears due to the catch, but that should have been obvious.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: Registry Reading

    Try the following way :
    RegistryKey rkey;
    rkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Blizzard Entertainment\World of Warcraft",true);

    also , try Convert.ToString function in the return snippet
    Last edited by Pirate; Jan 9th, 2009 at 01:32 PM.

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Registry Reading

    That's because you set rKey = HKLM key, and certainly the HKLM doesn't contain the subkey "InstallPath", so when you try to call ToString on rKey.GetValue("InstallPath"), you get null exeception. Pirate's code should work.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    59

    Re: Registry Reading

    Thanks guys.

    I must not have been following the tutorial properly

    All working.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width