Hi,

I'm pulling my hair out with this one, I need to populate a combobox with a list of servers from the registry, I think the code I've used is fairly sound, but when I run the project, I get the following error, which I'm sure you're all familiar with Null Reference Exception was Unhandled Object Reference not set to an instance of an object

private void Login_Load(object sender, EventArgs e)
        {
            string strKey = @"HKEY_CURRENT_USER\Software\Datasym UK\Stockade SQL\Server List";

            //if (IntPtr.Size == 8)
            //{
            //    strKey = @"SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server";
            //}

            RegistryKey rkSqlServer = Registry.LocalMachine.OpenSubKey(strKey);
          string[] instances = rkSqlServer.GetValue("InstalledInstances")[/COLOR]
            as string[];
            if (instances.GetUpperBound(0) >= 0)
            {
                 foreach (string element in instances)
                     if (element == "MSSQLSERVER")
                {
                    lstServers.Items.Add(Environment.MachineName);
                }
                else
                {
                    lstServers.Items.Add(Environment.MachineName + @"\" + element);
                }

            }
        }

As anyone any ideas as to where I may be going wrong?

Thanks,

R

instead of getvalue - which returns a single value and as you specified no default option, if not found, it would return null..

Do you not mean getsubkeynames?