-- To enumerate the values in a key:
EXEC master..xp_regenumvalues N'HKEY_LOCAL_MACHINE',
        N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Parameters'
-- Output can be piped to a temporary table & easily searched
CREATE TABLE #Reg ( Value nvarchar( 255 ) , Data nvarchar( 255 ) )
INSERT #Reg
EXEC master..xp_regenumvalues N'HKEY_LOCAL_MACHINE',
        N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Parameters'
SELECT * FROM #Reg
WHERE Data LIKE '-e%'

-- To get a single value in a registry key:
-- Output can be piped to a temporary table again.
EXEC master..xp_regread N'HKEY_LOCAL_MACHINE',
        N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Parameters',
        N'SQLArg1'

-- To get a single value in a registry key in a variable:
DECLARE @v varchar( 255 )
EXEC master..xp_regread N'HKEY_LOCAL_MACHINE',
        N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Parameters',
        N'SQLArg1' , @v OUT , N'no_output'
SELECT @v
go
-- To write a single value to a registry key:
DECLARE @v varchar( 255 )
SET @v = '-p38'
EXEC master..xp_regwrite N'HKEY_LOCAL_MACHINE',
        N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Parameters',
        N'SQLArg3' , N'REG_SZ' , @v
go
-- To delete a value from a registry key:
DECLARE @v varchar( 255 )
SET @v = 'SQLArg3'
EXEC master.dbo.xp_regdeletevalue N'HKEY_LOCAL_MACHINE',
        N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Parameters',
        @v
This page was last updated on May 01, 2006 04:28 PM.