Registry value

Last Post 18 Mar 2010 09:47 AM by PaulMcKibben. 5 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
PaulMcKibben
New Member
New Member

--
17 Mar 2010 08:18 AM
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
BEGIN
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?

Thank you.
russellb
New Member
New Member

--
17 Mar 2010 08:32 AM
Your code works fine for me. Even if I change it to a key that doesn't exist (then I get a zero)

Looks like a permissions error to me. Is the service account local admin on the host?

-- Russell --
---------------------------------
SQL Server Magazine Forum Pro
PaulMcKibben
New Member
New Member

--
17 Mar 2010 08:45 AM
Russell,

Thank you.

I don't believe it is a permission issue because I have a T-SQL that is using xp_regread to retrieve other registry values, and this is just another instance of xp_regread in that script. The server that I developing and testing the script against does not have the NumErrorLogs entry in the registry. I verified that by remoting to the server and running regedit.

The RegQueryValueEx() error is, as you know, not shown in the results area, it is in the messages.

Paul
russellb
New Member
New Member

--
17 Mar 2010 07:24 PM
Weird. Even if I change the @hive or @regkey to garbage, I just get a zero. What SP Level are you running this on?

-- Russell --
----------------------------------------
SQL Server Magazine Forum Pro
PaulMcKibben
New Member
New Member

--
18 Mar 2010 09:41 AM
We are running 2005 Standard SP3
PaulMcKibben
New Member
New Member

--
18 Mar 2010 09:47 AM
The @regvalue of 'NumErrorLogs' is not present under the @hive and @regkey combination. The results show a zero return code, but the messages show the message.

I wasn't sure if anyone had run across this before and had a solution. Since xp_regread is undo***ented there is little on the errors from it.

Thanks.
You are not authorized to post a reply.

Acceptable Use Policy