Winapi 无法删除注册表项

Winapi 无法删除注册表项,winapi,visual-c++,Winapi,Visual C++,我创建了一个新的注册表项。我无法删除父节点。登记册的结构如下: HKEY\U当前用户\软件\ IE\U备份\互联网设置 下面是我用来删除注册表项的代码。它删除节点InternetSettings的内容,但无法删除IE_备份 void main() { //some other stuffs of code are here for creating new registry. bool ret = DeleteValueKey(HKEY_CURRENT_USER, L"Software\

我创建了一个新的注册表项。我无法删除父节点。登记册的结构如下:

HKEY\U当前用户\软件\ IE\U备份\互联网设置 下面是我用来删除注册表项的代码。它删除节点InternetSettings的内容,但无法删除IE_备份

 void main()
 {  //some other stuffs of code are here for creating new registry.
 bool ret = DeleteValueKey(HKEY_CURRENT_USER, L"Software\\IE_BACKUP",L"Internet  Settings");


 }

bool DeleteValueKey(HKEY hKeyRoot, LPCWSTR Subkey, LPCWSTR ValueKey)
{
HKEY    hKey        = NULL;
bool    bReturn     = false;

    if (RegDeleteKey(hKey, Subkey ) == ERROR_SUCCESS)
    {
        bReturn = true;
    }
if (RegOpenKeyEx(hKeyRoot, Subkey, 0, KEY_SET_VALUE , &hKey) == ERROR_SUCCESS)
{                   
   if (RegDeleteKey(hKey, ValueKey ) == ERROR_SUCCESS)
    {
        bReturn = true;
    }
}

if(hKey != NULL){RegCloseKey(hKey);}

return bReturn;
}

它返回什么错误?RegDeleteKey(hKey,Subkey)返回值6,即error\u INVALID\u HANDLE。是的,因为
hKey=NULL前面两行。当函数不起作用时,您应该仔细检查参数。感谢RaymondChen,我将参数更改为RegDeleteKey(hKeyRoot,Subkey),返回值为5,即ERROR_ACCESS_DENIED。此代码设计得不好。当api调用失败时,它需要立即退出。