How can I get a list of installed SQL Server instances?
Today we’ll talk about how we can get a list of locally installed SQL Server instances on a system. This information is stored in the registry at the following location:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL
If you are looking for 32 bit instances on a 64 bit OS, you will need to look here:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\Instance Names\SQL
All we need to do is query this registry key to get the list of instances installed on a machine. On my personal machine, I have the following instances installed:
Below are a few ways we can get this information for 64 bit instances on 64 bit Windows:
Command shell “reg.exe” utility:
reg query "HKLM\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL"
Get-ItemProperty 'HKLM:\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL'
RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
RegistryKey key = baseKey.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL");
foreach (string s in key.GetValueNames())
If you need to read the registry from another computer, then the RegistryKey class has a “OpenRemoteBaseKey” static method that you can use.