Accessing Registry using XPs – TSQL
You can use the undocumented extended stored procedure xp_regread to access registry entries using T-SQL.
Syntax:
xp_regread @rootkey = N'rootkey',
@key = N'key',
@value_name = N'value_name',
@value = @outputValue OUTPUT
For example, below code returns "C:\Program Files" on my system :
DECLARE @returnValue NVARCHAR(100)
EXEC master.dbo.xp_regread
@rootkey = N'HKEY_LOCAL_MACHINE',
@key = N'SOFTWARE\\Microsoft\Windows\\CurrentVersion',
@value_name = N'ProgramFilesDir',
@value = @returnValue output
SELECT @returnValue
xp_regread ca only be used to retrieve a single value. If you need to retrieve multiple values, you will need to use xp_instance_regenumvalues, which returns all values under a specified key.
For example, To retrieve a list of start-up programs from registry we will use:
EXEC master..xp_instance_regenumvalues
@rootkey = N'HKEY_LOCAL_MACHINE',
@key = N'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run'
this will return all entries under HKLM\Software\Microsoft\Windows\CurrentVersion\Run:
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


how can we get time zone settings if they are set in the registry