There seems to be two Registry paths that contain the installation directory / folder:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions
The Installed Versions Key has sub-Keys for the SQL Server version in the form of 11.0, 12.0, and so on. Each version number Key has an InstanceAPIPath Value of type "REG_SZ" which contains Data such as:
C:\Program Files\Microsoft SQL Server\120\LocalDB\Binn\SqlUserInstance.dll
and
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server
The Microsoft SQL Server Key has sub-Keys for the LocalDB instances in the form of MSSQL11E.LOCALDB, MSSQL12E.LOCALDB, and so on. Each instance Key has a sub-Key for Setup, which in turn has a SQLBinRoot Value of type "REG_SZ" which contains Data such as:
C:\Program Files\Microsoft SQL Server\120\LocalDB\Binn\
P.S. If you have a folder for 130 then you do have SQL Server 2016 (or some component of it) installed since that is the version number for SQL Server 2016. 110 is for SQL Server 2012, 120 is for SQL Server 2014, and I don't believe a value of 140 currently exists (which, of course, would certainly make it very hard to confirm ;-).
Regarding Ramveer's answer: While it is true that you can have Registry entries for applications that are no longer installed, starting with the Registry is still more reliable than executing SqlLocalDB.exe as the containing folder is not required to be in the PATH
environment variable in order to work, but the registry entries most likely are required (i.e. you aren't going to have LocalDB installed and not have the Registry entries). But yes, it is still a good idea to test each reported installation folder to make sure that it is still there. You can do this in DOS / cmd script by running:
reg query "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server Local DB"
returns:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\11.0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\12.0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\13.0
You can use the DOS FOR
command to iterate over that output, capturing the version number (just the integer portion of 11
, 12
, etc and not the decimal portion of .0
that follows). Then, for each version number, check its registry Key to get the install folder (just replace the "12" in the path below with the extracted version number):
reg query "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12E.LOCALDB\Setup" /v "SQLBinRoot"
which returns:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12E.LOCALDB\Setup
SQLBinRoot REG_SZ C:\Program Files\Microsoft SQL Server\120\LocalDB\Binn\
You can again use the DOS FOR
command to capture that output and extract the path. Then, you can check for its existence and if it can actually run by doing the following:
REM You wouldn't need the following SET if extracting with the FOR command
SET CheckPath="C:\Program Files\Microsoft SQL Server\120\LocalDB\Binn\sqlservr.exe"
IF EXIST %CheckPath% ( %CheckPath% -v ) ELSE ( ECHO Not really here )