Here is the way to find SQL Server CD key, which was used to install it on machine. If user do not have permission on the SP, please login using SA username. Expended stored procedure xp_regread can read any registry values. I have used this XP to read CD_KEY. This is undocumented Stroed Procedure and may not be supported in Future Version of SQL Server.
USE master
GO
EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft
SQL Server\80\Registration','CD_KEY'
GO
Reference : Pinal Dave (http://blog.SQLAuthority.com)




Thanks, I’ve used this twice now..
BTW, when I cut and paste the code above, it uses ‘ (acute quotes) instead of ' which messed me up briefly.
This post is really useful. Thanks,
Also i need to know how to retrieve the Sql server Instance Name from the Registry.
I am using SQL Server2005 Express version.
Thanks
Good one …..Mr Dave
Can you explore some more Undocumented XP_ if possible plz send the link ..I will be great ful to u …thanx or u can send on my mail ID …i guess u have
Thanx in advance!! chief
What we can use for MSSQL 2005
CREATE PROC Reg_Get
AS
BEGIN
EXEC master.dbo.xp_regenumkeys ‘HKEY_LOCAL_MACHINE’,'SOFTWARE\ISS\CPE’
IF @@ERROR 0
BEGIN
RAISERROR (‘Key doesnt exists ‘,10,1 )
RETURN 1
END
RETURN 0
END
GO
– Calling Script
EXEC Reg_Get
– Result
Msg 22001, Level 16, State 1, Line 0
RegOpenKeyEx() returned error 2, ‘The system cannot find the file specified.’
I want to trap above error without using TRY..CATCH. So that It can support to SQL Server 2000 also
Hi
Is there any way of reading the regstry & getting to knw the SQL Server Instacnes on the particular box along with the version (2000 Or 2005)
Thanks
[...] SQL SERVER – T-SQL Script to find the CD key from Registry [...]