Using T-SQL to Manipulate the Registry

A reader describes four undocumented T-SQL extended stored procedures that you can use to work with the registry.

Readers

February 28, 2002

1 Min Read
ITPro Today logo in a gray background | ITPro Today

SQL Server 7.0 includes many undocumented extended stored procedures. Although you might not want to rely too heavily on them because Microsoft might remove or decide not to support them in a future SQL Server release, the procedures can be useful in specific situations. Here are four extended stored procedures that are useful for working with the registry. Members of the sysadmin fixed server role have execute permissions for these extended stored procedures by default, but administrators can grant permissions to other users.

  • xp_regwrite—This extended stored procedure creates new registry subkeys and subkey values. You can use xp_regwrite when you want to write something into the registry on the SQL Server from a client computer. To invoke xp_regwrite, use the syntax that Listing 3 shows. This code example creates a new subkey called Test that has the value TestValue in the HKEY_LOCAL_MACHINESOFTWARE subkey.

  • xp_regread—This extended stored procedure returns a value for a registry entry that you specify. To invoke xp_regread, use the syntax that Listing 4 shows. This code example returns a value for the HKEY_LOCAL_MACHINESOFTWARETestTestValue subkey into the @test variable.

  • xp_regdeletevalue—This extended stored procedure deletes a specified subkey's value from the registry. Use it carefully. To invoke xp_regdeletevalue, use the syntax that Listing 5 shows. This code example deletes the TestValue value from the HKEY_LOCAL_MACHINESOFTWARETest subkey.

  • xp_regdeletekey—This extended stored procedure deletes keys from the registry. Invoke it carefully by using the syntax that Listing 6 shows. This code example deletes the Test subkey from the HKEY_LOCAL_MACHINESOFTWARE subkey.

—Alexander Chigrik
[email protected]

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like