Home > SQLServer, SQLServer 2005, SQLServer 2008, SQLServer 2008 R2, Undocumented Functions > Accessing Registry using XPs (contd..) – TSQL

Accessing Registry using XPs (contd..) – TSQL

We can use the xp_regwrite undocumented extended stored procedure to write new entries to Windows registry.

You need to provide the key path, A new key will be created if it does not exist.

The following code will add a new entry in startup programs list in registry:

— © 2011 – Vishal (http://SqlAndMe.com)

EXEC master..xp_regwrite
     @rootkey     = 'HKEY_LOCAL_MACHINE',
     @key         = 'Software\Microsoft\Windows\CurrentVersion\Run',
     @value_name  = 'Solitaire',
     @type        = 'REG_SZ',
     @value       = 'C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe'

 

Output returned by the procedure will be '(0) rows affected', unless it encounters an error.

 

To verify the entry, you need to open Registry Editor and traverse to specified path.

 

image

 

Or you can also use xp_regread or xp_instance_regread to verify the entry.

 

You can delete an registry entry using xp_regdelete.

 

— © 2011 – Vishal (http://SqlAndMe.com)

EXEC master..xp_regdeletevalue
     @rootkey     = 'HKEY_LOCAL_MACHINE',
     @key         = 'Software\Microsoft\Windows\CurrentVersion\Run',
     @value_name  = 'Solitaire'

 

Output returned by the procedure will be '(0) rows affected', unless it encounters an error.

 

Hope This Helps!

Vishal

If you like this post, do like my Facebook Page -> SqlAndMe
EMail me your questions -> Vishal@SqlAndMe.com
Follow me on Twitter -> @SqlAndMe

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: