The information in this article applies to:
SUMMARY
In Windows 95, the RegDeleteKey function not only deletes the particular
key specified but also any subkey descendants. In contrast, the Windows NT
version of this function deletes only the particular key specified and will
not delete any key that has subkey descendants.
MORE INFORMATION
Starting at the particular key specified, each key is traversed by using
RegEnumKeyEx, which determines if there are any subkeys. If so, the
subkey's name is passed to the recursive delete function in order to
traverse to the next subkey. This process is repeated for all subkey
descendants. When RegEnumKeyEx reports that there are no more subkeys (that
is, ERROR_NO_MORE_ITEMS) for the current key, a subkey leaf has been
reached.
Partial DeletionsFailure to fully delete the particular key specified can be the result of 'partial deletions' (the failure to delete all available subkeys). Although partial deletions can result from several situations, one possible cause is individual key protection.To protect against partial deletions caused by protected keys, you should test each individual key to ensure that it is not protected from deletion. To test if the current user has deletion rights on all the keys to be deleted, you must traverse, enumerate, and open all subkeys with DELETE privilege requested:
If, however, between the time of the delete privilege test and the actual
attempt to delete, the key protection is altered, the recursive delete
function will still fail.
Note that the DELETE privilege is not explicitly defined in the RegOpenKeyEx() documentation under the "samDesired" parameter. But most securable objects under Windows NT, including registry keys, have a set of standard access rights that correspond to operations specific to that type of object. And, DELETE is one of these standard access rights that applies to all registry keys, in addition to READ_CONTROL, RIGHT_DAC, and RIGHT_OWNER rights. So, using the DELETE constant in the RegOpenKeyEx() call above will work correctly. To truly protect the registry against partial deletion, you need to follow a two-step process. First, prior to the deletion attempt, save the initial state of the registry path to be deleted. Then, to recover from a partial deletion, you could restore the registry to its former state using the information already saved. If partial deletions are acceptable, however, failure to delete a key could trigger the recursive delete function to fail or the key to be skipped. Sample Code
On Windows 98 and Windows 2000, it would probably be easier to use SHDeleteEmptyKey and SHDeleteKey, as these have clearly defined behavior on all platforms. However, there are limitations about the use of these APIs on Windows 95 and Windows NT 4.0, clarified in the documentation for these APIs.
Additional query words:
Keywords : kbcode kbKernBase kbNTOS350 kbNTOS351 kbNTOS400 kbWinOS2000 kbRegistry kbWinOS95 kbWinOS98 kbDSupport kbGrpKernBase |
Last Reviewed: January 6, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |