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_MACHINE\SOFTWARE 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_MACHINE\SOFTWARE\Test\TestValue 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_MACHINE\SOFTWARE\Test 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_MACHINE\SOFTWARE subkey.