Registry Extended Stored Procedures | Database Journal

Registry Extended Stored Procedures

Written By
Darren Green
Darren Green
Oct 20, 1999
1 minute read


Examples of how to read, write and delete registry values using SQL Server extended stored procedures.


These xp’s are not documented in SQL Server Books Online and therefore unsupported by Microsoft.


xp_regread


xp_regread [@rootkey=]rootkey,
[@key=]key[, [@value_name=]value_name][,
[@value=]@value OUTPUT]


1. Check for vaild key

EXEC master.dbo.xp_regread @rootkey='HKEY_LOCAL_MACHINE',   
  @key='SOFTWAREMicrosoftMSSQLServerMSSQLServer'
KeyExist    
----------- 
1


2. Read key as result set

EXEC master.dbo.xp_regread @rootkey='HKEY_LOCAL_MACHINE',   
  @key='SOFTWAREMicrosoftMSSQLServerMSSQLServer',
  @value_name='defaultLogin'
Value                Data  
-------------------- ------
defaultLogin         guest


3. Read key into variable

DECLARE @value varchar(25)
EXEC master.dbo.xp_regread @rootkey='HKEY_LOCAL_MACHINE',   
  @key='SOFTWAREMicrosoftMSSQLServerMSSQLServer', 
  @value_name='defaultLogin', @value=@value OUTPUT
PRINT @value
guest


xp_regwrite


xp_regwrite [@rootkey=]rootkey,
[@key=]key, [@value_name=]value_name,
[@type=]type, [@value=]value,


type can be REG_SZ for string values or REG_DWORD for integers


1. Write key and value

EXEC master.dbo.xp_regwrite @rootkey='HKEY_LOCAL_MACHINE',  
  @key='SOFTWARExp_reg', @value_name='URL', @type='REG_SZ',
  @value='http://www.swynk.com/friends/green/'


xp_regdeletekey


xp_regdeletekey [@rootkey=]rootkey,
[@key=]key


Beware, this will delete the whole key. Use Carefully.


1. Delete whole key

EXEC master.dbo.xp_regdeletekey                             
 @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARExp_reg'
Msg 22001, Level 1, State 22001
RegDeleteKey() returned error 0, 
  'The operation completed successfully.'
Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.