0
我想使用RegCopyTree将所有子项和值复制到另一个子项,但我得到错误代码5,这意味着访问被拒绝。拒绝访问拒绝RegCopyTree在C
我要求KEY_CREATE_SUB_KEY
访问,但它仍然失败。我也以管理员身份运行该应用程序,但它根本不起作用。
你能帮我吗?
这里是我的代码:
int wmain()
{
//RegOpenKeyEx
HKEY hKey = HKEY_CURRENT_USER;
LPCWSTR subKeyOpen = L"WinSide";
DWORD options = 0;
REGSAM samDesired = KEY_READ;
HKEY openedKey;
//Opening the HKCU\WinSide subkey
LONG openKey = RegOpenKeyEx(hKey, subKeyOpen, options,
samDesired, &openedKey);
LPCWSTR subKeyDest = L"WinSi";
REGSAM destSamDesired = KEY_CREATE_SUB_KEY;
HKEY destOpenedKey;
//Opening the HKCU\WinSi subkey - this is the destination subkey
LONG destOpenKey = RegOpenKeyEx(hKey, subKeyDest, options,
destSamDesired, &destOpenedKey);
if (openKey != ERROR_SUCCESS)
{
wprintf(L"Error opening the key. Code: %li\n", openKey);
}
else
{
wprintf(L"Key opened!\n");
if (destOpenKey != ERROR_SUCCESS)
wprintf(L"Error code: %li\n", destOpenKey);
else
{
//RegCopyTree
HKEY keyDest;
LONG copyKey = RegCopyTree(openedKey, NULL, destOpenedKey);
if (copyKey != ERROR_SUCCESS)
wprintf(L"Error copying the key. Code: %li\n", copyKey);
else
{
wprintf(L"Key copied!\n");
}
}
RegCloseKey(openedKey);
RegCloseKey(destOpenedKey);
}
return 0;
}
我在两个开口都用'KEY_WRITE'尝试过,但仍然出现同样的错误。 –
刚刚添加了答案。 –