I am trying to get all the instance names of SQL on a machine, all the values are held in a regkey here is my code, but I keep getting a null reference exception.
private void RegLoop()
{
     RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL")
      foreach (var v in key.GetValueNames())
      {
         MessageBox.Show("{0}", v);
      }
}
 
     
    