ReactOS 0.4.15-dev-8339-g4028de8
delete.c File Reference
#include "reg.h"
Include dependency graph for delete.c:

Go to the source code of this file.

Functions

static void output_error (LONG rc)
 
static int run_delete (HKEY root, WCHAR *path, REGSAM sam, WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL value_all, BOOL force)
 
int reg_delete (int argc, WCHAR *argvW[])
 

Variables

static BOOL op_delete_key = TRUE
 

Function Documentation

◆ output_error()

static void output_error ( LONG  rc)
static

Definition at line 23 of file delete.c.

24{
25 if (rc == ERROR_FILE_NOT_FOUND)
26 {
27 if (op_delete_key)
29 else
31 }
32 else
33 {
35 }
36}
static BOOL op_delete_key
Definition: delete.c:21
void WINAPIV output_message(unsigned int id,...)
Definition: reg.c:92
#define STRING_VALUE_NONEXIST
Definition: resource.h:39
#define STRING_KEY_NONEXIST
Definition: resource.h:38
#define STRING_ACCESS_DENIED
Definition: resource.h:35
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79

Referenced by run_delete().

◆ reg_delete()

int reg_delete ( int  argc,
WCHAR argvW[] 
)

Definition at line 134 of file delete.c.

135{
136 HKEY root;
137 WCHAR *path, *key_name, *value_name = NULL;
138 BOOL value_all = FALSE, value_empty = FALSE, force = FALSE;
139 REGSAM sam = 0;
140 int i;
141
142 if (!parse_registry_key(argvW[2], &root, &path))
143 return 1;
144
145 for (i = 3; i < argc; i++)
146 {
147 WCHAR *str;
148
149 if (argvW[i][0] != '/' && argvW[i][0] != '-')
150 goto invalid;
151
152 str = &argvW[i][1];
153
154 if (!lstrcmpiW(str, L"va"))
155 {
156 if (value_all) goto invalid;
157 value_all = TRUE;
158 continue;
159 }
160 else if (!lstrcmpiW(str, L"ve"))
161 {
162 if (value_empty) goto invalid;
163 value_empty = TRUE;
164 continue;
165 }
166 else if (!lstrcmpiW(str, L"reg:32"))
167 {
168 if (sam & KEY_WOW64_32KEY) goto invalid;
170 continue;
171 }
172 else if (!lstrcmpiW(str, L"reg:64"))
173 {
174 if (sam & KEY_WOW64_64KEY) goto invalid;
176 continue;
177 }
178 else if (!str[0] || str[1])
179 goto invalid;
180
181 switch (towlower(*str))
182 {
183 case 'v':
184 if (value_name || !(value_name = argvW[++i]))
185 goto invalid;
186 break;
187 case 'f':
188 if (force) goto invalid;
189 force = TRUE;
190 break;
191 default:
192 goto invalid;
193 }
194 }
195
196 if ((value_name && value_empty) || (value_name && value_all) || (value_empty && value_all))
197 goto invalid;
198
200 goto invalid;
201
203
204 return run_delete(root, path, sam, key_name, value_name, value_empty, value_all, force);
205
206invalid:
209 return 1;
210}
static int argc
Definition: ServiceArgs.c:12
static int run_delete(HKEY root, WCHAR *path, REGSAM sam, WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL value_all, BOOL force)
Definition: delete.c:38
static REGSAM sam
Definition: query.c:143
WCHAR * get_long_key(HKEY root, WCHAR *path)
Definition: reg.c:208
BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path)
Definition: reg.c:234
#define STRING_INVALID_SYNTAX
Definition: resource.h:33
#define STRING_FUNC_HELP
Definition: resource.h:34
struct _root root
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4261
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static const WCHAR invalid[]
Definition: assoc.c:39
#define L(x)
Definition: ntvdm.h:50
const WCHAR * str
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)
#define towlower(c)
Definition: wctype.h:97
ACCESS_MASK REGSAM
Definition: winreg.h:69
#define KEY_WOW64_32KEY
Definition: cmtypes.h:45
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by wmain().

◆ run_delete()

static int run_delete ( HKEY  root,
WCHAR path,
REGSAM  sam,
WCHAR key_name,
WCHAR value_name,
BOOL  value_empty,
BOOL  value_all,
BOOL  force 
)
static

Definition at line 38 of file delete.c.

40{
41 LONG rc;
42 HKEY hkey;
43
44 if (!force)
45 {
46 BOOL ret;
47
48 if (value_name || value_empty)
49 ret = ask_confirm(STRING_DELETE_VALUE, value_name);
50 else if (value_all)
52 else
54
55 if (!ret)
56 {
58 return 0;
59 }
60 }
61
62 if ((rc = RegOpenKeyExW(root, path, 0, KEY_READ|KEY_SET_VALUE|sam, &hkey)))
63 {
64 output_error(rc);
65 return 1;
66 }
67
68 /* Delete registry key if no /v* option is given */
69 if (!value_name && !value_empty && !value_all)
70 {
71 if ((rc = RegDeleteTreeW(hkey, NULL)))
72 {
73 RegCloseKey(hkey);
74 output_error(rc);
75 return 1;
76 }
77
78 RegDeleteKeyW(hkey, L"");
79 RegCloseKey(hkey);
80
82 return 0;
83 }
84
86
87 if (value_all)
88 {
89 DWORD max_value_len = 256, value_len;
90 WCHAR *value_name;
91
92 value_name = malloc(max_value_len * sizeof(WCHAR));
93
94 while (1)
95 {
96 value_len = max_value_len;
97 rc = RegEnumValueW(hkey, 0, value_name, &value_len, NULL, NULL, NULL, NULL);
98 if (rc == ERROR_SUCCESS)
99 {
100 rc = RegDeleteValueW(hkey, value_name);
101 if (rc != ERROR_SUCCESS)
102 {
103 free(value_name);
104 RegCloseKey(hkey);
106 output_error(rc);
107 return 1;
108 }
109 }
110 else if (rc == ERROR_MORE_DATA)
111 {
112 max_value_len *= 2;
113 value_name = realloc(value_name, max_value_len * sizeof(WCHAR));
114 }
115 else break;
116 }
117 free(value_name);
118 }
119 else if (value_name || value_empty)
120 {
121 if ((rc = RegDeleteValueW(hkey, value_name)))
122 {
123 RegCloseKey(hkey);
124 output_error(rc);
125 return 1;
126 }
127 }
128
129 RegCloseKey(hkey);
131 return 0;
132}
static void output_error(LONG rc)
Definition: delete.c:23
BOOL ask_confirm(unsigned int msgid, WCHAR *reg_info)
Definition: reg.c:127
#define STRING_VALUEALL_FAILED
Definition: resource.h:74
#define STRING_SUCCESS
Definition: resource.h:36
#define STRING_DELETE_VALUE
Definition: resource.h:71
#define STRING_CANCELLED
Definition: resource.h:37
#define STRING_DELETE_VALUEALL
Definition: resource.h:72
#define STRING_DELETE_SUBKEY
Definition: resource.h:73
#define RegCloseKey(hKey)
Definition: registry.h:49
LSTATUS WINAPI RegDeleteTreeW(_In_ HKEY, _In_opt_ LPCWSTR)
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1239
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
unsigned long DWORD
Definition: ntddk_ex.h:95
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_SET_VALUE
Definition: nt_native.h:1017
long LONG
Definition: pedump.c:60
int ret

Referenced by reg_delete().

Variable Documentation

◆ op_delete_key

BOOL op_delete_key = TRUE
static

Definition at line 21 of file delete.c.

Referenced by output_error(), and run_delete().