ReactOS 0.4.15-dev-7113-g9ea2222
registry.c
Go to the documentation of this file.
1/*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19/*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS system libraries
22 * FILE: dll/win32/userenv/registry.c
23 * PURPOSE: User profile code
24 * PROGRAMMER: Eric Kohl
25 */
26
27#include "precomp.h"
28
29#define NDEBUG
30#include <debug.h>
31
32/* FUNCTIONS ***************************************************************/
33
34static
35BOOL
36CopyKey(HKEY hDstKey,
37 HKEY hSrcKey)
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,
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,
132 return FALSE;
133 }
134
135 Error = RegCreateKeyExW(hDstKey,
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,
151 return FALSE;
152 }
153
154 Error = RegOpenKeyExW(hSrcKey,
156 0,
157 KEY_READ,
158 &hSrcSubKey);
159 if (Error != ERROR_SUCCESS)
160 {
161 DPRINT1("Error: %lu\n", Error);
162 RegCloseKey(hDstSubKey);
164 0,
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,
179 return FALSE;
180 }
181
182 RegCloseKey(hSrcSubKey);
183 RegCloseKey(hDstSubKey);
184 }
185
187 0,
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,
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,
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,
239 return FALSE;
240 }
241
242 Error = RegSetValueExW(hDstKey,
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,
258 return FALSE;
259 }
260 }
261
263 0,
264 lpDataBuffer);
265
267 0,
269 }
270
271 DPRINT("CopyKey() done\n");
272
273 return TRUE;
274#endif
275}
276
277
278BOOL
280 LPCWSTR lpProfilePath)
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
325Cleanup:
326 if (hUserKey != NULL)
327 RegCloseKey (hUserKey);
328
329 if (hDefaultKey != NULL)
330 RegCloseKey (hDefaultKey);
331
332 return Ret;
333}
334
335/* EOF */
#define DPRINT1
Definition: precomp.h:8
BOOL Error
Definition: chkdsk.c:66
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3353
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:2524
LONG WINAPI RegFlushKey(HKEY hKey)
Definition: reg.c:2971
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4902
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:2850
#define GetProcessHeap()
Definition: compat.h:736
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
BOOL UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath, HKEY hUserKey)
Definition: setup.c:434
BOOL CreateUserHive(LPCWSTR lpKeyName, LPCWSTR lpProfilePath)
Definition: registry.c:279
static BOOL CopyKey(HKEY hDstKey, HKEY hSrcKey)
Definition: registry.c:36
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
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
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_READ
Definition: nt_native.h:1023
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
static LPSTR lpNameBuffer
Definition: secur32.c:50
#define DPRINT
Definition: sndvol32.h:71
unsigned char * LPBYTE
Definition: typedefs.h:53
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define RegQueryInfoKey
Definition: winreg.h:521
#define HKEY_USERS
Definition: winreg.h:13
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185