regedit: Free the stringValueData buffer before using it again (Coverity).
[wine.git] / programs / regedit / edit.c
blobd88061cffcf38e04bd58da36b5d180c5cb840cea
1 /*
2 * Registry editing UI functions.
4 * Copyright (C) 2003 Dimitrie O. Paun
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
23 #include <windows.h>
24 #include <commctrl.h>
25 #include <commdlg.h>
26 #include <cderr.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <shellapi.h>
30 #include <shlwapi.h>
32 #include "wine/unicode.h"
33 #include "main.h"
34 #include "regproc.h"
35 #include "resource.h"
37 static const WCHAR* editValueName;
38 static WCHAR* stringValueData;
39 static BOOL isDecimal;
41 struct edit_params
43 HKEY hKey;
44 LPCWSTR lpszValueName;
45 void *pData;
46 LONG cbData;
49 static int vmessagebox(HWND hwnd, int buttons, int titleId, int resId, __ms_va_list va_args)
51 WCHAR title[256];
52 WCHAR fmt[1024];
53 WCHAR *str;
54 int ret;
56 LoadStringW(hInst, titleId, title, COUNT_OF(title));
57 LoadStringW(hInst, resId, fmt, COUNT_OF(fmt));
59 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
60 fmt, 0, 0, (WCHAR *)&str, 0, &va_args);
61 ret = MessageBoxW(hwnd, str, title, buttons);
62 LocalFree(str);
64 return ret;
67 int __cdecl messagebox(HWND hwnd, int buttons, int titleId, int resId, ...)
69 __ms_va_list ap;
70 INT result;
72 __ms_va_start(ap, resId);
73 result = vmessagebox(hwnd, buttons, titleId, resId, ap);
74 __ms_va_end(ap);
76 return result;
79 static void __cdecl error_code_messagebox(HWND hwnd, unsigned int msg_id, ...)
81 __ms_va_list ap;
83 __ms_va_start(ap, msg_id);
84 vmessagebox(hwnd, MB_OK|MB_ICONERROR, IDS_ERROR, msg_id, ap);
85 __ms_va_end(ap);
88 static BOOL change_dword_base(HWND hwndDlg, BOOL toHex)
90 static const WCHAR percent_u[] = {'%','u',0};
91 static const WCHAR percent_x[] = {'%','x',0};
93 WCHAR buf[128];
94 DWORD val;
96 if (!GetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, buf, COUNT_OF(buf))) return FALSE;
97 if (!swscanf(buf, toHex ? percent_u : percent_x, &val)) return FALSE;
98 wsprintfW(buf, toHex ? percent_x : percent_u, val);
99 return SetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, buf);
102 static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
104 WCHAR* valueData;
105 HWND hwndValue;
106 int len;
108 switch(uMsg) {
109 case WM_INITDIALOG:
110 SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, editValueName);
111 SetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, stringValueData);
112 CheckRadioButton(hwndDlg, IDC_DWORD_HEX, IDC_DWORD_DEC, isDecimal ? IDC_DWORD_DEC : IDC_DWORD_HEX);
113 return TRUE;
114 case WM_COMMAND:
115 switch (LOWORD(wParam)) {
116 case IDC_DWORD_HEX:
117 if (isDecimal && change_dword_base(hwndDlg, TRUE)) isDecimal = FALSE;
118 break;
119 case IDC_DWORD_DEC:
120 if (!isDecimal && change_dword_base(hwndDlg, FALSE)) isDecimal = TRUE;
121 break;
122 case IDOK:
123 if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
124 len = GetWindowTextLengthW(hwndValue);
125 if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(WCHAR)))) {
126 stringValueData = valueData;
127 if (!GetWindowTextW(hwndValue, stringValueData, len + 1))
128 *stringValueData = 0;
131 /* Fall through */
132 case IDCANCEL:
133 EndDialog(hwndDlg, wParam);
134 return TRUE;
137 return FALSE;
140 static INT_PTR CALLBACK bin_modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
142 struct edit_params *params;
143 LPBYTE pData;
144 LONG cbData;
145 LONG lRet;
147 switch(uMsg) {
148 case WM_INITDIALOG:
149 params = (struct edit_params *)lParam;
150 SetWindowLongPtrW(hwndDlg, DWLP_USER, (ULONG_PTR)params);
151 if (params->lpszValueName)
152 SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, params->lpszValueName);
153 else
154 SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, g_pszDefaultValueName);
155 SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_SETDATA, (WPARAM)params->cbData, (LPARAM)params->pData);
156 return TRUE;
157 case WM_COMMAND:
158 switch (LOWORD(wParam)) {
159 case IDOK:
160 params = (struct edit_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
161 cbData = SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, 0, 0);
162 pData = HeapAlloc(GetProcessHeap(), 0, cbData);
164 if (pData)
166 SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, (WPARAM)cbData, (LPARAM)pData);
167 lRet = RegSetValueExW(params->hKey, params->lpszValueName, 0, REG_BINARY, pData, cbData);
169 else
170 lRet = ERROR_OUTOFMEMORY;
172 if (lRet == ERROR_SUCCESS)
173 EndDialog(hwndDlg, 1);
174 else
176 error_code_messagebox(hwndDlg, IDS_SET_VALUE_FAILED);
177 EndDialog(hwndDlg, 0);
179 return TRUE;
180 case IDCANCEL:
181 EndDialog(hwndDlg, 0);
182 return TRUE;
185 return FALSE;
188 static BOOL check_value(HWND hwnd, HKEY hKey, LPCWSTR valueName)
190 WCHAR empty = 0;
191 LONG lRet = RegQueryValueExW(hKey, valueName ? valueName : &empty, 0, NULL, 0, NULL);
192 if(lRet != ERROR_SUCCESS) return FALSE;
193 return TRUE;
196 static LPWSTR read_value(HWND hwnd, HKEY hKey, LPCWSTR valueName, DWORD *lpType, LONG *len)
198 DWORD valueDataLen;
199 LPWSTR buffer = NULL;
200 LONG lRet;
201 WCHAR empty = 0;
203 lRet = RegQueryValueExW(hKey, valueName ? valueName : &empty, 0, lpType, 0, &valueDataLen);
204 if (lRet != ERROR_SUCCESS) {
205 if (lRet == ERROR_FILE_NOT_FOUND && !valueName) { /* no default value here, make it up */
206 if (len) *len = 1;
207 if (lpType) *lpType = REG_SZ;
208 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR));
209 *buffer = '\0';
210 return buffer;
212 error_code_messagebox(hwnd, IDS_BAD_VALUE, valueName);
213 goto done;
215 if ( *lpType == REG_DWORD ) valueDataLen = sizeof(DWORD);
216 if (!(buffer = HeapAlloc(GetProcessHeap(), 0, valueDataLen+sizeof(WCHAR)))) {
217 error_code_messagebox(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
218 goto done;
220 lRet = RegQueryValueExW(hKey, valueName, 0, 0, (LPBYTE)buffer, &valueDataLen);
221 if (lRet != ERROR_SUCCESS) {
222 error_code_messagebox(hwnd, IDS_BAD_VALUE, valueName);
223 goto done;
225 if((valueDataLen % sizeof(WCHAR)) == 0)
226 buffer[valueDataLen / sizeof(WCHAR)] = 0;
227 if(len) *len = valueDataLen;
228 return buffer;
230 done:
231 HeapFree(GetProcessHeap(), 0, buffer);
232 return NULL;
235 BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR keyName)
237 BOOL result = FALSE;
238 LONG lRet = ERROR_SUCCESS;
239 HKEY retKey = NULL;
240 WCHAR newKey[MAX_NEW_KEY_LEN - 4];
241 int keyNum;
242 HKEY hKey;
244 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_CREATE_SUB_KEY, &hKey);
245 if (lRet != ERROR_SUCCESS) {
246 error_code_messagebox(hwnd, IDS_CREATE_KEY_FAILED);
247 goto done;
250 if (!LoadStringW(GetModuleHandleW(0), IDS_NEWKEY, newKey, COUNT_OF(newKey))) goto done;
252 /* try to find a name for the key being created (maximum = 100 attempts) */
253 for (keyNum = 1; keyNum < 100; keyNum++) {
254 wsprintfW(keyName, newKey, keyNum);
255 lRet = RegOpenKeyW(hKey, keyName, &retKey);
256 if (lRet != ERROR_SUCCESS) break;
257 RegCloseKey(retKey);
259 if (lRet == ERROR_SUCCESS) goto done;
261 lRet = RegCreateKeyW(hKey, keyName, &retKey);
262 if (lRet != ERROR_SUCCESS) {
263 error_code_messagebox(hwnd, IDS_CREATE_KEY_FAILED);
264 goto done;
267 result = TRUE;
269 done:
270 RegCloseKey(retKey);
271 return result;
274 BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
276 BOOL result = FALSE;
277 DWORD type;
278 LONG lRet;
279 HKEY hKey;
280 LONG len;
282 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
283 if (lRet != ERROR_SUCCESS) {
284 error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
285 return FALSE;
288 editValueName = valueName ? valueName : g_pszDefaultValueName;
289 if(!(stringValueData = read_value(hwnd, hKey, valueName, &type, &len))) goto done;
291 if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
292 if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_STRING), hwnd, modify_dlgproc) == IDOK) {
293 lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, (lstrlenW(stringValueData) + 1) * sizeof(WCHAR));
294 if (lRet == ERROR_SUCCESS) result = TRUE;
295 else error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
297 } else if ( type == REG_DWORD ) {
298 const WCHAR u[] = {'%','u',0};
299 const WCHAR x[] = {'%','x',0};
300 wsprintfW(stringValueData, isDecimal ? u : x, *((DWORD*)stringValueData));
301 if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_DWORD), hwnd, modify_dlgproc) == IDOK) {
302 DWORD val;
303 CHAR* valueA = GetMultiByteString(stringValueData);
304 if (sscanf(valueA, isDecimal ? "%u" : "%x", &val)) {
305 lRet = RegSetValueExW(hKey, valueName, 0, type, (BYTE*)&val, sizeof(val));
306 if (lRet == ERROR_SUCCESS) result = TRUE;
307 else error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
309 HeapFree(GetProcessHeap(), 0, valueA);
311 } else if ( type == REG_BINARY ) {
312 struct edit_params params;
313 params.hKey = hKey;
314 params.lpszValueName = valueName;
315 params.pData = stringValueData;
316 params.cbData = len;
317 result = DialogBoxParamW(NULL, MAKEINTRESOURCEW(IDD_EDIT_BINARY), hwnd,
318 bin_modify_dlgproc, (LPARAM)&params);
319 } else if ( type == REG_MULTI_SZ ) {
320 WCHAR char1 = '\r', char2 = '\n';
321 WCHAR *tmpValueData = NULL;
322 INT i, j, count;
324 for ( i = 0, count = 0; i < len - 1; i++)
325 if ( !stringValueData[i] && stringValueData[i + 1] )
326 count++;
327 tmpValueData = HeapAlloc( GetProcessHeap(), 0, ( len + count ) * sizeof(WCHAR));
328 if ( !tmpValueData ) goto done;
330 for ( i = 0, j = 0; i < len - 1; i++)
332 if ( !stringValueData[i] && stringValueData[i + 1])
334 tmpValueData[j++] = char1;
335 tmpValueData[j++] = char2;
337 else
338 tmpValueData[j++] = stringValueData[i];
340 tmpValueData[j] = stringValueData[i];
341 HeapFree( GetProcessHeap(), 0, stringValueData);
342 stringValueData = tmpValueData;
343 tmpValueData = NULL;
345 if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_MULTI_STRING), hwnd, modify_dlgproc) == IDOK)
347 len = lstrlenW( stringValueData );
348 tmpValueData = HeapAlloc( GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR));
349 if ( !tmpValueData ) goto done;
351 for ( i = 0, j = 0; i < len - 1; i++)
353 if ( stringValueData[i] == char1 && stringValueData[i + 1] == char2)
355 if ( tmpValueData[j - 1] != 0)
356 tmpValueData[j++] = 0;
357 i++;
359 else
360 tmpValueData[j++] = stringValueData[i];
362 tmpValueData[j++] = stringValueData[i];
363 tmpValueData[j++] = 0;
364 tmpValueData[j++] = 0;
365 HeapFree( GetProcessHeap(), 0, stringValueData);
366 stringValueData = tmpValueData;
368 lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, j * sizeof(WCHAR));
369 if (lRet == ERROR_SUCCESS) result = TRUE;
370 else error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
372 } else {
373 error_code_messagebox(hwnd, IDS_UNSUPPORTED_TYPE, type);
376 /* Update the listview item with the new data string */
377 if (result)
379 int index = SendMessageW(g_pChildWnd->hListWnd, LVM_GETNEXTITEM, -1,
380 MAKELPARAM(LVNI_FOCUSED | LVNI_SELECTED, 0));
381 HeapFree(GetProcessHeap(), 0, stringValueData);
382 stringValueData = read_value(hwnd, hKey, valueName, &type, &len);
383 format_value_data(g_pChildWnd->hListWnd, index, type, stringValueData, len);
386 done:
387 HeapFree(GetProcessHeap(), 0, stringValueData);
388 stringValueData = NULL;
389 RegCloseKey(hKey);
390 return result;
393 BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath)
395 BOOL result = FALSE;
396 LONG lRet;
397 HKEY hKey;
399 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ|KEY_SET_VALUE, &hKey);
400 if (lRet != ERROR_SUCCESS) {
401 error_code_messagebox(hwnd, IDS_DELETE_KEY_FAILED);
402 return FALSE;
405 if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_KEY_TITLE, IDS_DELETE_KEY_TEXT, keyPath) != IDYES)
406 goto done;
408 lRet = SHDeleteKeyW(hKeyRoot, keyPath);
409 if (lRet != ERROR_SUCCESS) {
410 error_code_messagebox(hwnd, IDS_BAD_KEY, keyPath);
411 goto done;
413 result = TRUE;
415 done:
416 RegCloseKey(hKey);
417 return result;
420 BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName, BOOL showMessageBox)
422 BOOL result = FALSE;
423 LONG lRet;
424 HKEY hKey;
425 LPCWSTR visibleValueName = valueName ? valueName : g_pszDefaultValueName;
426 WCHAR empty = 0;
428 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
429 if (lRet != ERROR_SUCCESS) return FALSE;
431 if (showMessageBox)
433 if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_VALUE_TITLE, IDS_DELETE_VALUE_TEXT,
434 visibleValueName) != IDYES)
435 goto done;
438 lRet = RegDeleteValueW(hKey, valueName ? valueName : &empty);
439 if (lRet != ERROR_SUCCESS && valueName) {
440 error_code_messagebox(hwnd, IDS_BAD_VALUE, valueName);
442 if (lRet != ERROR_SUCCESS) goto done;
443 result = TRUE;
445 done:
446 RegCloseKey(hKey);
447 return result;
450 BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, DWORD valueType, LPWSTR valueName)
452 LONG lRet = ERROR_SUCCESS;
453 WCHAR newValue[256];
454 DWORD valueDword = 0;
455 BOOL result = FALSE;
456 int valueNum, index;
457 HKEY hKey;
458 LVITEMW item;
460 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
461 if (lRet != ERROR_SUCCESS) {
462 error_code_messagebox(hwnd, IDS_CREATE_VALUE_FAILED);
463 return FALSE;
466 if (!LoadStringW(GetModuleHandleW(0), IDS_NEWVALUE, newValue, COUNT_OF(newValue))) goto done;
468 /* try to find a name for the value being created (maximum = 100 attempts) */
469 for (valueNum = 1; valueNum < 100; valueNum++) {
470 wsprintfW(valueName, newValue, valueNum);
471 lRet = RegQueryValueExW(hKey, valueName, 0, 0, 0, 0);
472 if (lRet == ERROR_FILE_NOT_FOUND) break;
474 if (lRet != ERROR_FILE_NOT_FOUND) {
475 error_code_messagebox(hwnd, IDS_CREATE_VALUE_FAILED);
476 goto done;
479 lRet = RegSetValueExW(hKey, valueName, 0, valueType, (BYTE*)&valueDword, sizeof(DWORD));
480 if (lRet != ERROR_SUCCESS) {
481 error_code_messagebox(hwnd, IDS_CREATE_VALUE_FAILED);
482 goto done;
485 /* Add the new item to the listview */
486 index = AddEntryToList(g_pChildWnd->hListWnd, valueName, valueType, (BYTE *)&valueDword, sizeof(DWORD));
487 item.state = LVIS_FOCUSED | LVIS_SELECTED;
488 item.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
489 SendMessageW(g_pChildWnd->hListWnd, LVM_SETITEMSTATE, index, (LPARAM)&item);
491 result = TRUE;
493 done:
494 RegCloseKey(hKey);
495 return result;
498 BOOL RenameValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR oldName, LPCWSTR newName)
500 LPWSTR value = NULL;
501 DWORD type;
502 LONG len, lRet;
503 BOOL result = FALSE;
504 HKEY hKey;
506 if (!oldName) return FALSE;
507 if (!newName) return FALSE;
509 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
510 if (lRet != ERROR_SUCCESS) {
511 error_code_messagebox(hwnd, IDS_RENAME_VALUE_FAILED);
512 return FALSE;
514 /* check if the value already exists */
515 if (check_value(hwnd, hKey, newName)) {
516 error_code_messagebox(hwnd, IDS_VALUE_EXISTS, oldName);
517 goto done;
519 value = read_value(hwnd, hKey, oldName, &type, &len);
520 if(!value) goto done;
521 lRet = RegSetValueExW(hKey, newName, 0, type, (BYTE*)value, len);
522 if (lRet != ERROR_SUCCESS) {
523 error_code_messagebox(hwnd, IDS_RENAME_VALUE_FAILED);
524 goto done;
526 lRet = RegDeleteValueW(hKey, oldName);
527 if (lRet != ERROR_SUCCESS) {
528 RegDeleteValueW(hKey, newName);
529 error_code_messagebox(hwnd, IDS_RENAME_VALUE_FAILED);
530 goto done;
532 result = TRUE;
534 done:
535 HeapFree(GetProcessHeap(), 0, value);
536 RegCloseKey(hKey);
537 return result;
541 BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCWSTR keyPath, LPCWSTR newName)
543 LPWSTR parentPath = 0;
544 LPCWSTR srcSubKey = 0;
545 HKEY parentKey = 0;
546 HKEY destKey = 0;
547 BOOL result = FALSE;
548 LONG lRet;
549 DWORD disposition;
551 if (!keyPath || !newName) return FALSE;
553 if (!strrchrW(keyPath, '\\')) {
554 parentKey = hRootKey;
555 srcSubKey = keyPath;
556 } else {
557 LPWSTR srcSubKey_copy;
559 parentPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(keyPath)+1)*sizeof(WCHAR));
560 lstrcpyW(parentPath, keyPath);
561 srcSubKey_copy = strrchrW(parentPath, '\\');
562 *srcSubKey_copy = 0;
563 srcSubKey = srcSubKey_copy + 1;
564 lRet = RegOpenKeyExW(hRootKey, parentPath, 0, KEY_READ | KEY_CREATE_SUB_KEY, &parentKey);
565 if (lRet != ERROR_SUCCESS) {
566 error_code_messagebox(hwnd, IDS_RENAME_KEY_FAILED);
567 goto done;
571 /* The following fails if the old name is the same as the new name. */
572 if (!lstrcmpW(srcSubKey, newName)) goto done;
574 lRet = RegCreateKeyExW(parentKey, newName, 0, NULL, REG_OPTION_NON_VOLATILE,
575 KEY_WRITE, NULL /* FIXME */, &destKey, &disposition);
576 if (disposition == REG_OPENED_EXISTING_KEY)
577 lRet = ERROR_FILE_EXISTS;
578 if (lRet != ERROR_SUCCESS) {
579 error_code_messagebox(hwnd, IDS_KEY_EXISTS, srcSubKey);
580 goto done;
583 /* FIXME: SHCopyKey does not copy the security attributes */
584 lRet = SHCopyKeyW(parentKey, srcSubKey, destKey, 0);
585 if (lRet != ERROR_SUCCESS) {
586 RegCloseKey(destKey);
587 RegDeleteKeyW(parentKey, newName);
588 error_code_messagebox(hwnd, IDS_RENAME_KEY_FAILED);
589 goto done;
592 lRet = SHDeleteKeyW(hRootKey, keyPath);
593 if (lRet != ERROR_SUCCESS) {
594 error_code_messagebox(hwnd, IDS_RENAME_KEY_FAILED);
595 goto done;
598 result = TRUE;
600 done:
601 RegCloseKey(destKey);
602 if (parentKey) {
603 RegCloseKey(parentKey);
604 HeapFree(GetProcessHeap(), 0, parentPath);
606 return result;