TheRandomLabs Incorporated TheRandomLabs Incorporated - 3 months ago 49
C++ Question

How to use RegCopyTree

I'm playing around with the C++ registry functions, and I'm trying to get RegCopyTree working, but every time I try I get an error like

ERROR_FILE_NOT_FOUND


or

ERROR_ACCESS_DENIED.


I am running the program as administrator, and all other registry functions work fine.

Here is the code that I'm using:

HKEY destinationKey;
RegCreateKeyEx(getRootKeyFromCode(rootKeyCode),
destinationKeyPathNative, 0, NULL, 0, 0, NULL,
&destinationKey, NULL);
RegCopyTree(INSERT_ROOT_KEY_HERE,
INSERT_ORIGINAL_KEY_PATH_HERE, destinationKey);
RegCloseKey(destinationKey);


I've removed the error handling and some other irrelevant parts.

Could somebody show me some working code that uses RegCopyTree?

Answer

Destination key handle should have write access, to be able to copy to it. Calling RegCreateKeyEx() without specifying access mode either fails or doesn't grant write access. Try with KEY_WRITE or KEY_CREATE_SUB_KEY as sixth argument.