Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cant delete reg entries in certain areas, why ?

Status
Not open for further replies.

skinah

Programmer
Oct 3, 2001
17
AU
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);
}
 
Don't mix using of Reg* functions with SH* functions. Use only Reg* at all, or only SH* at atll. In your case use RegDeleteKey instead of SHDeleteKey.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top