Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/delete.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/programs/reg/delete.c b/programs/reg/delete.c index f8e62e490b9..8804e16e52f 100644 --- a/programs/reg/delete.c +++ b/programs/reg/delete.c @@ -18,9 +18,27 @@
#include "reg.h"
+static BOOL op_delete_key = TRUE; + +static void output_error(LONG rc) +{ + if (rc == ERROR_FILE_NOT_FOUND) + { + if (op_delete_key) + output_message(STRING_KEY_NONEXIST); + else + output_message(STRING_VALUE_NONEXIST); + } + else + { + output_message(STRING_ACCESS_DENIED); + } +} + static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL value_all, BOOL force) { + LONG rc; HKEY hkey;
if (!force) @@ -44,26 +62,28 @@ static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name /* Delete registry key if no /v* option is given */ if (!value_name && !value_empty && !value_all) { - if (RegDeleteTreeW(root, path) != ERROR_SUCCESS) + if ((rc = RegDeleteTreeW(root, path))) { - output_message(STRING_KEY_NONEXIST); + output_error(rc); return 1; } + output_message(STRING_SUCCESS); return 0; }
- if (RegOpenKeyExW(root, path, 0, KEY_READ|KEY_SET_VALUE, &hkey)) + if ((rc = RegOpenKeyExW(root, path, 0, KEY_READ|KEY_SET_VALUE, &hkey))) { - output_message(STRING_KEY_NONEXIST); + output_error(rc); return 1; }
+ op_delete_key = FALSE; + if (value_all) { DWORD max_value_len = 256, value_len; WCHAR *value_name; - LONG rc;
value_name = malloc(max_value_len * sizeof(WCHAR));
@@ -79,6 +99,7 @@ static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name free(value_name); RegCloseKey(hkey); output_message(STRING_VALUEALL_FAILED, key_name); + output_error(rc); return 1; } } @@ -93,10 +114,10 @@ static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name } else if (value_name || value_empty) { - if (RegDeleteValueW(hkey, value_name)) + if ((rc = RegDeleteValueW(hkey, value_name))) { RegCloseKey(hkey); - output_message(STRING_VALUE_NONEXIST); + output_error(rc); return 1; } }
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/reg.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc index 9dea8cfcb1a..c0d75f55b6c 100644 --- a/programs/reg/reg.rc +++ b/programs/reg/reg.rc @@ -131,7 +131,7 @@ STRINGTABLE STRING_DELETE_VALUEALL, "Are you sure you want to delete all registry values in '%1'?" STRING_DELETE_SUBKEY, "Are you sure you want to delete the registry key '%1'?" STRING_INVALID_STRING, "reg: The option [/d] must be followed by a valid string\n" - STRING_VALUEALL_FAILED, "reg: Unable to delete all registry values in '%1'. An unexpected error occurred.\n" + STRING_VALUEALL_FAILED, "reg: Unable to delete all registry values in '%1'\n" STRING_GENERAL_FAILURE, "reg: Unable to complete the specified operation. An unexpected error occurred.\n" STRING_MATCHES_FOUND, "Search complete. Number of matches found: %1!d!\n" STRING_INVALID_SYNTAX, "reg: Invalid syntax. "
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/add.c | 2 +- programs/reg/reg.rc | 2 +- programs/reg/resource.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/programs/reg/add.c b/programs/reg/add.c index 0236dfb4742..fb0ee2a03fd 100644 --- a/programs/reg/add.c +++ b/programs/reg/add.c @@ -76,7 +76,7 @@ static BOOL get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, unsigned long val; val = wcstoul(data, &rest, (towlower(data[1]) == 'x') ? 16 : 10); if (*rest || data[0] == '-' || (val == ~0u && errno == ERANGE)) { - output_message(STRING_MISSING_INTEGER); + output_message(STRING_MISSING_NUMBER); return FALSE; } *size_bytes = sizeof(DWORD); diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc index c0d75f55b6c..117365547ca 100644 --- a/programs/reg/reg.rc +++ b/programs/reg/reg.rc @@ -118,7 +118,7 @@ STRINGTABLE STRING_NO_REMOTE, "reg: Unable to access remote machine\n" STRING_VALUE_NONEXIST, "reg: Unable to find the specified registry value\n" STRING_UNSUPPORTED_TYPE, "reg: Unsupported registry data type [%1]\n" - STRING_MISSING_INTEGER, "reg: The option [/d] must be followed by a valid integer\n" + STRING_MISSING_NUMBER, "reg: The option [/d] must be followed by a valid numeric value\n" STRING_MISSING_HEXDATA, "reg: The option [/d] must be followed by a valid hexadecimal value\n" STRING_UNHANDLED_TYPE, "reg: Unhandled registry data type [/t 0x%1!x!, /d %2]\n" STRING_OVERWRITE_VALUE, "The registry value '%1' already exists. Do you want to overwrite it?" diff --git a/programs/reg/resource.h b/programs/reg/resource.h index b569eb41d3d..ecc4c09337c 100644 --- a/programs/reg/resource.h +++ b/programs/reg/resource.h @@ -31,7 +31,7 @@ #define STRING_NO_REMOTE 108 #define STRING_VALUE_NONEXIST 109 #define STRING_UNSUPPORTED_TYPE 110 -#define STRING_MISSING_INTEGER 111 +#define STRING_MISSING_NUMBER 111 #define STRING_MISSING_HEXDATA 112 #define STRING_UNHANDLED_TYPE 113 #define STRING_OVERWRITE_VALUE 114