Is there a way to verify that the registry value is present in the registy other than executing xp_regread and receiving a "RegQueryValueEx() returned error 2, 'The system cannot find the file specified.'
Msg 22001, Level 1, State 1" error?
I am using xp_regread to return the value of a registry entry, and I know that it is undo***ented. HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\MSSQL.1\
MSSQLServer\NumErrorLog is the key that I am retrieving.
My code is:
SELECT @hive = 'HKEY_LOCAL_MACHINE'
SELECT @regkey = N'Software\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer'
INSERT INTO #keyexist
EXECUTE master.dbo.xp_regread @hive, @regkey
SELECT @keyexist = keyexist FROM #keyexist
-- If @keyexist is equal to 1, the @hive and @regkey combination is found
IF @keyexist = 1
SELECT @regvalue = 'NumErrorLogs'
EXECUTE @rc = master.dbo.xp_regread @hive, @regkey, @regvalue,
@data OUTPUT, N'no output'
In my current code @rc is equal to zero. Is there a way to verify that the registry is present? Or is there a way to capture the return code 2?