Xp_regread is an undocumented stored procedure. It enables you to read the literal registry path that you specify via T-SQL.

EXEC [master].[dbo].[xp_regread] @rootkey='HKEY_LOCAL_MACHINE',
@key='Software\Microsoft\MSSQLServer\Setup',
@value_name='SQLPath'

[code]

You can use the OUTPUT parameter with xp_regread to return the value back.

[code language="sql"]

declare @outputValue nvarchar (128)
EXEC [master].[dbo].[xp_regread] @rootkey='HKEY_LOCAL_MACHINE',
@key='Software\Microsoft\MSSQLServer\Setup',
@value_name='SQLPath',
@value = @outputValue OUTPUT
SELECT @outputValue

You can check who has access to xp_regread by running the following query;

SELECT
OBJECT_NAME(major_id) AS [Extended Stored Procedure],
USER_NAME(grantee_principal_id) AS [User]
FROM
sys.database_permissions
WHERE
OBJECT_NAME(major_ID) ='xp_regread'

As of SQL Server 2012 installations it appears that the public role gets the permission by default.