Wayne Sheffield shows how to read and modify registry entries using SQL Server:
xp_instance_regread
In this example, I used xp_regread to read the direct registry path. If you remember from earlier, there are SQL Server instance-aware versions of each registry procedure. A comparable statement using the instance-aware procedure would be:
1234 EXECUTE master.sys.xp_instance_regread‘HKEY_LOCAL_MACHINE’,‘Software\Microsoft\MSSQLSERVER\SQLServerAgent’,‘WorkingDirectory’;This statement returns the exact same information. Let’s look at the difference between these – in the first query, the registry path is the exact registry path needed, and it includes “\Microsoft SQL Server\MSSQL12.SQL2014\”. In the latter query, this string is replaced with “\MSSQLSERVER\”. Since the latter function is instance aware, it replaces the “MSSQLSERVER” with the exact registry path necessary for this instance of SQL Server. Pretty neat, isn’t it? This allows you to have a script that will run properly regardless of the instance that it is being run on. The rest of the examples in this post will utilize the instance-aware procedures to make it easier for you to follow along and run these yourself.
Sometimes you just have to change something in the registry from SQL Server. Hopefully that “sometimes” is rare.