SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP

Read Registry using SQL Server xp_regread SQL Stored Procedure

xp_regread sql stored procedure can be used to read registry key values in t-sql codes on a MS SQL Server database server.

xp_regread sql extended stored procedure is one of the undocumented stored procedures. Microsoft does not support use of undocumented stored procedures in SQL Server production environments, you it is your own risk to use xp_regread sql procedure in critical applications.

How can sql developers read registry key values using t-sql xp_regread stored procedure ?
Let's go over the xp_regread syntax together.

xp_regread Syntax

EXECUTE xp_regread
  @rootkey = 'root_key',
  @key = 'registry_key',
  @value_name = 'value_name',
  @value = @registry_value OUTPUT

Before we start, I want to remind once more that it is not recommended to use xp_regread sql stored procedure on production systems by Microsoft services.

Sample xp_regread SQL Script

Let's build a xp_regread sql stored procedure statement by considering the syntax of xp_regread proc.
The below sql script can be used to get the WinRAR open command and the install path of the WinRar application.


SET @key = 'WinRAR\shell\open\command'

EXEC master..xp_regread
 @rootkey = 'HKEY_CLASSES_ROOT',
 @key = @key,
 @value_name = NULL,
 @value = @value OUTPUT

SELECT @value

For an other xp_regread sample t-sql script which is used to find port number SQL Server using as TCP port, please refer to Sample xp_regread SQL Procedure Statement to find TCP Port Number.

If you experience RegQueryValueEx() sql error because of improper key value name when you execute xp_regread sql extended procedure, you can refer to article titled xp_regread - RegQueryValueEx() returned error 2, 'The system cannot find the file specified.'

SQL Server

SQL Server 2019 Installation
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014
download SQL Server 2012
MacOS ve SQL Server 2019

Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.