Reputation: 1070
I'm using the 64-bit installation mode and I have to check which version of MS SQL starting from MS SQL 2005 is installed on my machine. I can do it like this:
if RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Microsoft SQL Server\XXX\Tools\ClientSetup\CurrentVersion', 'CurrentVersion', RegValue) then
SQLVERSIONINSTALLED := RegValue;
where XXX are different for different versions of MS SQL.
In 64-bit install mode HKLM
relates to the 64-bit view of the registry by default. Do I have to check both the registry views using HKLM
and HKLM32
for versions lower than 2016? What is the safest and the most effective way to do that?
Upvotes: 0
Views: 532
Reputation: 81
How about using
SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\CurrentVersion
?
I believe it is on XP, Win8 and Win10
Upvotes: 0
Reputation: 5472
I don't see any performance problems with reading version twice (for 32/64 bit). Maybe you could put the versions in an array and perform checking in a loop:
var
sqlKeys: array of string;
sqlKeys := ['15.0', '16.0', '17.0'];
for I := low(sqlKeys) to high(sqlKeys) do
begin
if RegQueryStringValue(HKLM32, 'SOFTWARE\Microsoft\Microsoft SQL Server\' + sqlKeys[I] + '\Tools\ClientSetup\CurrentVersion', 'CurrentVersion', RegValue) then
SQLVERSIONINSTALLED := RegValue;
if RegQueryStringValue(HKLM64, 'SOFTWARE\Microsoft\Microsoft SQL Server\' + sqlKeys[I] + '\Tools\ClientSetup\CurrentVersion', 'CurrentVersion', RegValue) then
SQLVERSIONINSTALLED := RegValue;
end
Upvotes: 2