Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Oct 19, 1999

Registry Extended Stored Procedures

By Darren Green

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='SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\'
KeyExist    
----------- 
1

2. Read key as result set

EXEC master.dbo.xp_regread @rootkey='HKEY_LOCAL_MACHINE',   
  @key='SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\',
  @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='SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\', 
  @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='SOFTWARE\xp_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='SOFTWARE\xp_reg'
Msg 22001, Level 1, State 22001
RegDeleteKey() returned error 0, 
  'The operation completed successfully.'


MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM


















Thanks for your registration, follow us on our social networks to keep up-to-date