I cant seem to delete keys in this path..
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum
it works for all other areas. The same goes for enumerating the subkeys I cant do it unless I set KEY_READ which means I cant delete the keys. If i open the key to enumerate with KEY_ALL_ACCESS then it wont enumerate the subkeys. Any ideas ?
heres the code...
int RegKeyEnum(CString StrHkey, CString StrKey, CString StrName)
{
CString str, delname;
HKEY hKey;
HKEY hKey2;
long lResult;
char szBuffer[100];
DWORD dwBufferSize = 100;
LONG i;
HKEY root;
DWORD retCode, dwKeySize = MAX_PATH;
DWORD dwIndex=0;
FILETIME ftime;
CHAR achKey[MAX_PATH];
if(StrHkey == "HKEY_CURRENT_USER"
{lResult = RegOpenKeyEx(HKEY_CURRENT_USER, StrKey, 0, KEY_ALL_ACCESS, &hKey);}
else if(StrHkey == "HKEY_LOCAL_MACHINE"{lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, StrKey, 0, KEY_ALL_ACCESS, &hKey); }
else if(StrHkey == "HKEY_CURRENT_CONFIG"{lResult = RegOpenKeyEx(HKEY_CURRENT_CONFIG, StrKey, 0, KEY_ALL_ACCESS, &hKey); }
else if(StrHkey == "HKEY_USERS"{lResult = RegOpenKeyEx(HKEY_USERS, StrKey, 0, KEY_ALL_ACCESS, &hKey); }
else {MessageBox(NULL,"Registry Root not found",StrHkey,NULL);return 0;}
// Check for Error
if ( lResult != ERROR_SUCCESS)
{
MessageBox(NULL,"Registry Path does not exsist",StrKey,NULL);
return 0;
}
if ( lResult == ERROR_SUCCESS)
{
for (i = 0, retCode = ERROR_SUCCESS; retCode == ERROR_SUCCESS; i++)
{retCode = RegEnumKeyEx(hKey,i,achKey,&dwKeySize,NULL,NULL,NULL,&ftime);
delname=StrKey+"\\";
delname=delname+achKey;
MessageBox(NULL,delname,"hKey2",NULL);
SHDeleteKey(hKey,achKey);
}
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum
it works for all other areas. The same goes for enumerating the subkeys I cant do it unless I set KEY_READ which means I cant delete the keys. If i open the key to enumerate with KEY_ALL_ACCESS then it wont enumerate the subkeys. Any ideas ?
heres the code...
int RegKeyEnum(CString StrHkey, CString StrKey, CString StrName)
{
CString str, delname;
HKEY hKey;
HKEY hKey2;
long lResult;
char szBuffer[100];
DWORD dwBufferSize = 100;
LONG i;
HKEY root;
DWORD retCode, dwKeySize = MAX_PATH;
DWORD dwIndex=0;
FILETIME ftime;
CHAR achKey[MAX_PATH];
if(StrHkey == "HKEY_CURRENT_USER"
{lResult = RegOpenKeyEx(HKEY_CURRENT_USER, StrKey, 0, KEY_ALL_ACCESS, &hKey);}
else if(StrHkey == "HKEY_LOCAL_MACHINE"{lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, StrKey, 0, KEY_ALL_ACCESS, &hKey); }
else if(StrHkey == "HKEY_CURRENT_CONFIG"{lResult = RegOpenKeyEx(HKEY_CURRENT_CONFIG, StrKey, 0, KEY_ALL_ACCESS, &hKey); }
else if(StrHkey == "HKEY_USERS"{lResult = RegOpenKeyEx(HKEY_USERS, StrKey, 0, KEY_ALL_ACCESS, &hKey); }
else {MessageBox(NULL,"Registry Root not found",StrHkey,NULL);return 0;}
// Check for Error
if ( lResult != ERROR_SUCCESS)
{
MessageBox(NULL,"Registry Path does not exsist",StrKey,NULL);
return 0;
}
if ( lResult == ERROR_SUCCESS)
{
for (i = 0, retCode = ERROR_SUCCESS; retCode == ERROR_SUCCESS; i++)
{retCode = RegEnumKeyEx(hKey,i,achKey,&dwKeySize,NULL,NULL,NULL,&ftime);
delname=StrKey+"\\";
delname=delname+achKey;
MessageBox(NULL,delname,"hKey2",NULL);
SHDeleteKey(hKey,achKey);
}