Advertisement Jump to content
Sign in to follow this  
Kryptus

Registry Problem

This topic is 4915 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an XML file with a list of games in it. What I have done (and trying to do) is have my program scan for those games on the computer by checking the registry. I am using C#. I use the code below:
// My registry key object
RegistryKey myKey = Registry.LocalMachine;
// Get the registry key from the XML file and open it
myKey.OpenSubKey(game.GetAttribute("location"), false);

The last line of code here is in a loop, and it keeps looping until it reaches the end of the list. Let's say for example, I don't have Warcraft 3 installed but that game is in the list. It's gonna open the sub key. The problem is this code just loads the key regardless of it's existence!! Is there some way of detecting if a registry key exists? I tried the following code but it didn't work. I got a "Object reference not set to instance of object" error:
foreach (XmlElement game in games)
            {
                try
                {
                    myKey.OpenSubKey(game.GetAttribute("location"), false);

                    if (myKey.GetValue(game.GetAttribute("value")).ToString() == null)
                    {
                        //
                    }
                    else
                    {
                        // Add the game to the list
                        lvGames.Items.Add(game.GetAttribute("name"));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

And the XML loading code is fine. So don't worry about the XML part. I think the error lies with the IF statement ???

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!