Bonjour,
Je cherche à écrire une fonction qui aurait pour but de supprimer toutes les sous-clés d'une clé, à condition bien sûr que les sous-clés ne contiennent pas elles-même des sous-clés.
Je n'y arrive que partiellement, je m'explique :
Je cherche à supprimer les cinq sous-clé a, b, c, d, e de la clé TEST :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 void DeleteSubkeysOfOneKey(HKEY hKey, struct s_registre *ptr_registre) { HKEY hKeyDelSubkey; DWORD retCode; DWORD cSubKeys; int i; DWORD cbName; TCHAR achKey[MAX_KEY_LENGTH]; retCode = RegQueryInfoKey(hKey, NULL, NULL, NULL, &cSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (cSubKeys != 0) { for (i=0; i<cSubKeys; i++) { cbName = MAX_KEY_LENGTH; retCode = RegEnumKeyEx(hKey, i, achKey, &cbName, NULL, NULL, NULL, NULL); if (retCode == ERROR_SUCCESS) { retCode = RegDeleteKey(hKey, achKey); if (retCode != ERROR_SUCCESS) { printf("%s\\%s\n", ptr_registre->handle, achKey); printf(" error : deletion of this subkey failed...\n"); } else printf("Deleted !\n"); } else printf("Subkey%d=%s\\%s\\%s\n\n\n", i, ptr_registre->handle, ptr_registre->path, achKey); } } }
Et j'obtiens ça comme résultat à l'écran :HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\a
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\b
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\c
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\d
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e
Et donc deux sous-clés ne sont pas supprimées :Subkey0=Deleted !
Subkey1=Deleted !
Subkey2=Deleted !
Subkey3=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e
Subkey4=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e
En gros, une sous-clé sur deux n'est pas supprimée... pourtant, lorsque je lis les clés, avec la même boucle for que ci-dessus, j'obtiens :HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\b
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\d
Je ne comprends pas comment la fonction RegEnumKeyEx peut changer de comportement alors que le code est strictement identique.HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\a
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\b
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\c
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\d
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TEST\e
Merci par avance de votre aide.
Partager