You can scan for instance names in the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL\
From there you can take each name and the data column (e.g. a named instance 'SQL2008' might say 'MSSQL10.SQL2008'), and find the version by appending the instance identifier ('MSSQL.SQL2008') to this reg path:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\
MSSQL10.SQL2008\MSSQLServer\CurrentVersion\
In that key, there will be an entry called "CurrentVersion" and the data value will have the version #.
This will return a string like 11.0.2316.0
. In this case you only really care about the characters before the second decimal. If this reflects 10.0 or greater, that's SQL Server 2008 or greater (10.0 = 2008, 10.5 = 2008 R2, 11.0 = 2012). If this reflects 9.0 or less, that's something before 2008 (9.0 = 2005, 8.0 = 2000, etc).