ReactOS  0.4.14-dev-317-g96040ec
registry.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for registry.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static BOOL CopyKey (HKEY hDstKey, HKEY hSrcKey)
 
BOOL CreateUserHive (LPCWSTR lpKeyName, LPCWSTR lpProfilePath)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 29 of file registry.c.

Function Documentation

◆ CopyKey()

static BOOL CopyKey ( HKEY  hDstKey,
HKEY  hSrcKey 
)
static

Definition at line 36 of file registry.c.

38 {
39  LONG Error;
40 
41 #if (_WIN32_WINNT >= 0x0600)
42  Error = RegCopyTreeW(hSrcKey,
43  NULL,
44  hDstKey);
45  if (Error != ERROR_SUCCESS)
46  {
48  return FALSE;
49  }
50 
51  return TRUE;
52 
53 #else
54  FILETIME LastWrite;
55  DWORD dwSubKeys;
56  DWORD dwValues;
57  DWORD dwType;
58  DWORD dwMaxSubKeyNameLength;
59  DWORD dwSubKeyNameLength;
60  DWORD dwMaxValueNameLength;
61  DWORD dwValueNameLength;
62  DWORD dwMaxValueLength;
63  DWORD dwValueLength;
64  DWORD dwDisposition;
65  DWORD i;
67  LPBYTE lpDataBuffer;
68  HKEY hDstSubKey;
69  HKEY hSrcSubKey;
70 
71  DPRINT ("CopyKey() called \n");
72 
73  Error = RegQueryInfoKey(hSrcKey,
74  NULL,
75  NULL,
76  NULL,
77  &dwSubKeys,
78  &dwMaxSubKeyNameLength,
79  NULL,
80  &dwValues,
81  &dwMaxValueNameLength,
82  &dwMaxValueLength,
83  NULL,
84  NULL);
85  if (Error != ERROR_SUCCESS)
86  {
87  DPRINT1("RegQueryInfoKey() failed (Error %lu)\n", Error);
89  return FALSE;
90  }
91 
92  dwMaxSubKeyNameLength++;
93  dwMaxValueNameLength++;
94 
95  DPRINT("dwSubKeys %lu\n", dwSubKeys);
96  DPRINT("dwMaxSubKeyNameLength %lu\n", dwMaxSubKeyNameLength);
97  DPRINT("dwValues %lu\n", dwValues);
98  DPRINT("dwMaxValueNameLength %lu\n", dwMaxValueNameLength);
99  DPRINT("dwMaxValueLength %lu\n", dwMaxValueLength);
100 
101  /* Copy subkeys */
102  if (dwSubKeys != 0)
103  {
105  0,
106  dwMaxSubKeyNameLength * sizeof(WCHAR));
107  if (lpNameBuffer == NULL)
108  {
109  DPRINT1("Buffer allocation failed\n");
111  return FALSE;
112  }
113 
114  for (i = 0; i < dwSubKeys; i++)
115  {
116  dwSubKeyNameLength = dwMaxSubKeyNameLength;
117  Error = RegEnumKeyExW(hSrcKey,
118  i,
119  lpNameBuffer,
120  &dwSubKeyNameLength,
121  NULL,
122  NULL,
123  NULL,
124  &LastWrite);
125  if (Error != ERROR_SUCCESS)
126  {
127  DPRINT1("Subkey enumeration failed (Error %lu)\n", Error);
129  0,
130  lpNameBuffer);
132  return FALSE;
133  }
134 
135  Error = RegCreateKeyExW(hDstKey,
136  lpNameBuffer,
137  0,
138  NULL,
140  KEY_WRITE,
141  NULL,
142  &hDstSubKey,
143  &dwDisposition);
144  if (Error != ERROR_SUCCESS)
145  {
146  DPRINT1("Subkey creation failed (Error %lu)\n", Error);
148  0,
149  lpNameBuffer);
151  return FALSE;
152  }
153 
154  Error = RegOpenKeyExW(hSrcKey,
155  lpNameBuffer,
156  0,
157  KEY_READ,
158  &hSrcSubKey);
159  if (Error != ERROR_SUCCESS)
160  {
161  DPRINT1("Error: %lu\n", Error);
162  RegCloseKey(hDstSubKey);
164  0,
165  lpNameBuffer);
167  return FALSE;
168  }
169 
170  if (!CopyKey(hDstSubKey,
171  hSrcSubKey))
172  {
173  DPRINT1("Error: %lu\n", GetLastError());
174  RegCloseKey (hSrcSubKey);
175  RegCloseKey (hDstSubKey);
177  0,
178  lpNameBuffer);
179  return FALSE;
180  }
181 
182  RegCloseKey(hSrcSubKey);
183  RegCloseKey(hDstSubKey);
184  }
185 
187  0,
188  lpNameBuffer);
189  }
190 
191  /* Copy values */
192  if (dwValues != 0)
193  {
195  0,
196  dwMaxValueNameLength * sizeof(WCHAR));
197  if (lpNameBuffer == NULL)
198  {
199  DPRINT1("Buffer allocation failed\n");
201  return FALSE;
202  }
203 
204  lpDataBuffer = HeapAlloc(GetProcessHeap(),
205  0,
206  dwMaxValueLength);
207  if (lpDataBuffer == NULL)
208  {
209  DPRINT1("Buffer allocation failed\n");
211  0,
212  lpNameBuffer);
214  return FALSE;
215  }
216 
217  for (i = 0; i < dwValues; i++)
218  {
219  dwValueNameLength = dwMaxValueNameLength;
220  dwValueLength = dwMaxValueLength;
221  Error = RegEnumValueW(hSrcKey,
222  i,
223  lpNameBuffer,
224  &dwValueNameLength,
225  NULL,
226  &dwType,
227  lpDataBuffer,
228  &dwValueLength);
229  if (Error != ERROR_SUCCESS)
230  {
231  DPRINT1("Error: %lu\n", Error);
233  0,
234  lpDataBuffer);
236  0,
237  lpNameBuffer);
239  return FALSE;
240  }
241 
242  Error = RegSetValueExW(hDstKey,
243  lpNameBuffer,
244  0,
245  dwType,
246  lpDataBuffer,
247  dwValueLength);
248  if (Error != ERROR_SUCCESS)
249  {
250  DPRINT1("Error: %lu\n", Error);
252  0,
253  lpDataBuffer);
255  0,
256  lpNameBuffer);
258  return FALSE;
259  }
260  }
261 
263  0,
264  lpDataBuffer);
265 
267  0,
268  lpNameBuffer);
269  }
270 
271  DPRINT("CopyKey() done \n");
272 
273  return TRUE;
274 #endif
275 }
LONG WINAPI RegCloseKey(IN HKEY hKey)
Definition: registry.c:512
#define TRUE
Definition: types.h:120
#define RegQueryInfoKey
Definition: winreg.h:521
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCreateKeyExW(IN HKEY hKey, IN LPCWSTR lpSubKey, IN DWORD Reserved, IN LPWSTR lpClass OPTIONAL, IN DWORD dwOptions, IN REGSAM samDesired, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes OPTIONAL, OUT PHKEY phkResult, OUT LPDWORD lpdwDisposition OPTIONAL)
Definition: registry.c:533
#define KEY_READ
Definition: nt_native.h:1023
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LONG WINAPI RegSetValueExW(IN HKEY hKey, IN LPCWSTR lpValueName OPTIONAL, IN ULONG Reserved, IN ULONG dwType, IN const UCHAR *lpData, IN ULONG cbData)
Definition: registry.c:656
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
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
static BOOL CopyKey(HKEY hDstKey, HKEY hSrcKey)
Definition: registry.c:36
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:2853
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static LPSTR lpNameBuffer
Definition: secur32.c:50
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define SetLastError(x)
Definition: compat.h:409
#define DPRINT1
Definition: precomp.h:8
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
LONG WINAPI RegCopyTreeW(IN HKEY hKeySrc, IN LPCWSTR lpSubKey OPTIONAL, IN HKEY hKeyDest)
Definition: reg.c:736
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by CreateUserHive().

◆ CreateUserHive()

BOOL CreateUserHive ( LPCWSTR  lpKeyName,
LPCWSTR  lpProfilePath 
)

Definition at line 279 of file registry.c.

281 {
282  HKEY hDefaultKey = NULL;
283  HKEY hUserKey = NULL;
284  LONG Error;
285  BOOL Ret = FALSE;
286 
287  DPRINT("CreateUserHive(%S) called\n", lpKeyName);
288 
290  L".Default",
291  0,
292  KEY_READ,
293  &hDefaultKey);
294  if (Error != ERROR_SUCCESS)
295  {
297  goto Cleanup;
298  }
299 
301  lpKeyName,
302  0,
304  &hUserKey);
305  if (Error != ERROR_SUCCESS)
306  {
308  goto Cleanup;
309  }
310 
311  if (!CopyKey(hUserKey, hDefaultKey))
312  {
313  goto Cleanup;
314  }
315 
316  if (!UpdateUsersShellFolderSettings(lpProfilePath,
317  hUserKey))
318  {
319  goto Cleanup;
320  }
321 
322  RegFlushKey(hUserKey);
323  Ret = TRUE;
324 
325 Cleanup:
326  if (hUserKey != NULL)
327  RegCloseKey (hUserKey);
328 
329  if (hDefaultKey != NULL)
330  RegCloseKey (hDefaultKey);
331 
332  return Ret;
333 }
#define HKEY_USERS
Definition: winreg.h:13
LONG WINAPI RegCloseKey(IN HKEY hKey)
Definition: registry.c:512
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
LONG WINAPI RegFlushKey(HKEY hKey)
Definition: reg.c:2974
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
static BOOL CopyKey(HKEY hDstKey, HKEY hSrcKey)
Definition: registry.c:36
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define SetLastError(x)
Definition: compat.h:409
static const WCHAR L[]
Definition: oid.c:1250
static const WCHAR Cleanup[]
Definition: register.c:80
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
BOOL UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath, HKEY hUserKey)
Definition: setup.c:434

Referenced by CreateUserProfileExW().