Witam, mam problem z usunięciem klucza znajdującego się w kluczu głównym HKEY_LOCAL_MACHINE. Używam funkcji WinAPI, przeczytałem parę tekstów na ten temat i szczerze mówiąc - mam problem, którego nie potrafię sobie wytłumaczyc. Dlaczego jeśli tworze sobie drzewo kluczy w HKEY_LOCAL_MACHINE i identyczne drzewo w HKEY_CURRENT_USER to w pierwszym przypadku nie działa mi to jak trzeba, a w drugim już tak. Do rzeczy - wrzucę krótki fragment kodu, który zobrazuje mój problem.
Drzewo kluczy które chce usuwać wygląda tak:
-klucz glowny (LOCAL_MACHINE/CURRENT_USER)
--SOFTWARE/Software
---TEST
----test
-----1.1
------1.1.1
-------1.1.1.1
-------1.1.1.2
chce usunąć klucz 1.1...
Robię to prostą rekurencją (nie chciałem używać funkcji SHDeleteKey) i mam pytanie:
Dlaczego to działa...
#define WIN_LEAN_AND_MEAN
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow)
{
HKEY hKey,hKey2,hKey3;
LONG result1,result2,result3;
result1=RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\TEST\\test\\1.1\\1.1.1", 0, KEY_ALL_ACCESS, &hKey);
if(result1==ERROR_SUCCESS)
{
RegDeleteKey(hKey,"1.1.1.1");
RegDeleteKey(hKey,"1.1.1.2");
RegCloseKey(hKey);
result2=RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\TEST\\test\\1.1", 0, KEY_ALL_ACCESS, &hKey2);
if(result2==ERROR_SUCCESS)
{
RegDeleteKey(hKey2,"1.1.1");
RegCloseKey(hKey2);
result3=RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\TEST\\test", 0, KEY_ALL_ACCESS, &hKey3);
if(result3==ERROR_SUCCESS)
{
RegDeleteKey(hKey3,"1.1");
RegCloseKey(hKey3);
}
}
}
return 0;
}
...a to nie działa...
#define WIN_LEAN_AND_MEAN
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow)
{
HKEY hKey,hKey2,hKey3;
LONG result1,result2,result3;
result1=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\TEST\\test\\1.1\\1.1.1", 0, KEY_ALL_ACCESS, &hKey);
if(result1==ERROR_SUCCESS)
{
RegDeleteKey(hKey,"1.1.1.1");
RegDeleteKey(hKey,"1.1.1.2");
RegCloseKey(hKey);
result2=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\TEST\\test\\1.1", 0, KEY_ALL_ACCESS, &hKey2);
if(result2==ERROR_SUCCESS)
{
RegDeleteKey(hKey2,"1.1.1");
RegCloseKey(hKey2);
result3=RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\TEST\\test", 0, KEY_ALL_ACCESS, &hKey3);
if(result3==ERROR_SUCCESS)
{
RegDeleteKey(hKey3,"1.1");
RegCloseKey(hKey3);
}
}
}
return 0;
}