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 SQL Server and T-SQL Development Tutorials
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Windows, Windows Phone, SAP and ABAP, like SAP UI5, Screen Personas, etc.




download SQL Server 2017
download SQL Server 2016
download SQL Server 2014



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.

DECLARE @value VARCHAR(100)
DECLARE @key VARCHAR(100)

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.'






Related SQL Resources

SQL Server Articles

SQL Server 2012

SQL Server Tools

SQL Blog

MS SQL Server Forums









Copyright © 2004 - 2017 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems