Skip to content

Commit 3e1b16a

Browse files
committed
#3356 fix for xp_regread. Moved temp table out of try catch
1 parent 0b5071c commit 3e1b16a

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

sp_Blitz.sql

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ AS
265265
END; /*We need this permission to execute trace stuff, apparently*/
266266

267267
IF ISNULL(@SkipXPRegRead, 0) != 1 /*If @SkipXPRegRead hasn't been set to 1 by the caller*/
268-
BEGIN TRY
268+
BEGIN
269269
IF OBJECT_ID(N'tempdb..#XpRegReadTest') IS NULL
270270
BEGIN
271271
CREATE TABLE #XpRegReadTest
@@ -275,25 +275,28 @@ AS
275275
);
276276
END;
277277

278-
INSERT INTO #XpRegReadTest
279-
(
280-
[Value]
281-
,[Data]
282-
)
283-
EXEC xp_regread @rootkey = N'HKEY_LOCAL_MACHINE',
284-
@key = N'',
285-
@value_name = N'';
286-
287-
SET @SkipXPRegRead = 0; /*We can execute xp_regread*/
278+
BEGIN TRY
279+
INSERT INTO #XpRegReadTest
280+
(
281+
[Value]
282+
,[Data]
283+
)
284+
EXEC xp_regread @rootkey = N'HKEY_LOCAL_MACHINE',
285+
@key = N'',
286+
@value_name = N'';
287+
288+
SET @SkipXPRegRead = 0; /*We can execute xp_regread*/
289+
END TRY
290+
BEGIN CATCH
291+
SET @SkipXPRegRead = 1; /*We have don't have execute rights or xp_regread throws an error so skip it*/
292+
END CATCH;
288293

289294
IF OBJECT_ID(N'tempdb..#XpRegReadTest') IS NOT NULL
290295
BEGIN
291296
DROP TABLE #XpRegReadTest;
292297
END;
293-
END TRY
294-
BEGIN CATCH
295-
SET @SkipXPRegRead = 1; /*We have don't have execute rights or xp_regread throws an error so skip it*/
296-
END CATCH; /*Need execute on xp_regread*/
298+
END; /*Need execute on xp_regread*/
299+
297300

298301
IF NOT EXISTS
299302
(

0 commit comments

Comments
 (0)