2 * Copyright 2016-2017, 2021 Hugh McMaster
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 int reg_delete(HKEY root
, WCHAR
*path
, WCHAR
*key_name
, WCHAR
*value_name
,
22 BOOL value_empty
, BOOL value_all
, BOOL force
)
30 if (value_name
|| value_empty
)
31 ret
= ask_confirm(STRING_DELETE_VALUE
, value_name
);
33 ret
= ask_confirm(STRING_DELETE_VALUEALL
, key_name
);
35 ret
= ask_confirm(STRING_DELETE_SUBKEY
, key_name
);
39 output_message(STRING_CANCELLED
);
44 /* Delete subtree only if no /v* option is given */
45 if (!value_name
&& !value_empty
&& !value_all
)
47 if (RegDeleteTreeW(root
, path
) != ERROR_SUCCESS
)
49 output_message(STRING_CANNOT_FIND
);
52 output_message(STRING_SUCCESS
);
56 if (RegOpenKeyW(root
, path
, &key
) != ERROR_SUCCESS
)
58 output_message(STRING_CANNOT_FIND
);
64 DWORD max_value_len
= 256, value_len
;
68 value_name
= malloc(max_value_len
* sizeof(WCHAR
));
72 value_len
= max_value_len
;
73 rc
= RegEnumValueW(key
, 0, value_name
, &value_len
, NULL
, NULL
, NULL
, NULL
);
74 if (rc
== ERROR_SUCCESS
)
76 rc
= RegDeleteValueW(key
, value_name
);
77 if (rc
!= ERROR_SUCCESS
)
81 output_message(STRING_VALUEALL_FAILED
, key_name
);
85 else if (rc
== ERROR_MORE_DATA
)
88 value_name
= realloc(value_name
, max_value_len
* sizeof(WCHAR
));
94 else if (value_name
|| value_empty
)
96 if (RegDeleteValueW(key
, value_empty
? NULL
: value_name
) != ERROR_SUCCESS
)
99 output_message(STRING_CANNOT_FIND
);
105 output_message(STRING_SUCCESS
);