The following code will list all the SQL Server instances on the local machine.
RegistryView rv = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32;
using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, rv))
{
RegistryKey rk = hklm.OpenSubKey(@"SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL", false);
if (rk == null) return;
foreach(var v in rk.GetValueNames())
{
Console.WriteLine($"{v} : {rk.GetValue(v)}");
}
}
Console.ReadLine();
… assuming the registry is correct