3 * Copyright (C) 2004 ReactOS Team
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.
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.
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.
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
33 /* FUNCTIONS ***************************************************************/
42 #if (_WIN32_WINNT >= 0x0600)
43 Error
= RegCopyTreeW(hSrcKey
,
46 if (Error
!= ERROR_SUCCESS
)
48 SetLastError((DWORD
)Error
);
59 DWORD dwMaxSubKeyNameLength
;
60 DWORD dwSubKeyNameLength
;
61 DWORD dwMaxValueNameLength
;
62 DWORD dwValueNameLength
;
63 DWORD dwMaxValueLength
;
72 DPRINT ("CopyKey() called \n");
74 Error
= RegQueryInfoKey(hSrcKey
,
79 &dwMaxSubKeyNameLength
,
82 &dwMaxValueNameLength
,
86 if (Error
!= ERROR_SUCCESS
)
88 DPRINT1("RegQueryInfoKey() failed (Error %lu)\n", Error
);
89 SetLastError((DWORD
)Error
);
93 DPRINT("dwSubKeys %lu\n", dwSubKeys
);
94 DPRINT("dwMaxSubKeyNameLength %lu\n", dwMaxSubKeyNameLength
);
95 DPRINT("dwValues %lu\n", dwValues
);
96 DPRINT("dwMaxValueNameLength %lu\n", dwMaxValueNameLength
);
97 DPRINT("dwMaxValueLength %lu\n", dwMaxValueLength
);
102 lpNameBuffer
= HeapAlloc(GetProcessHeap(),
104 dwMaxSubKeyNameLength
* sizeof(WCHAR
));
105 if (lpNameBuffer
== NULL
)
107 DPRINT1("Buffer allocation failed\n");
108 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
112 for (i
= 0; i
< dwSubKeys
; i
++)
114 dwSubKeyNameLength
= dwMaxSubKeyNameLength
;
115 Error
= RegEnumKeyExW(hSrcKey
,
123 if (Error
!= ERROR_SUCCESS
)
125 DPRINT1("Subkey enumeration failed (Error %lu)\n", Error
);
126 HeapFree(GetProcessHeap(),
129 SetLastError((DWORD
)Error
);
133 Error
= RegCreateKeyExW(hDstKey
,
137 REG_OPTION_NON_VOLATILE
,
142 if (Error
!= ERROR_SUCCESS
)
144 DPRINT1("Subkey creation failed (Error %lu)\n", Error
);
145 HeapFree(GetProcessHeap(),
148 SetLastError((DWORD
)Error
);
152 Error
= RegOpenKeyExW(hSrcKey
,
157 if (Error
!= ERROR_SUCCESS
)
159 DPRINT1("Error: %lu\n", Error
);
160 RegCloseKey(hDstSubKey
);
161 HeapFree(GetProcessHeap(),
164 SetLastError((DWORD
)Error
);
168 if (!CopyKey(hDstSubKey
,
171 DPRINT1("Error: %lu\n", GetLastError());
172 RegCloseKey (hSrcSubKey
);
173 RegCloseKey (hDstSubKey
);
174 HeapFree(GetProcessHeap(),
180 RegCloseKey(hSrcSubKey
);
181 RegCloseKey(hDstSubKey
);
184 HeapFree(GetProcessHeap(),
192 lpNameBuffer
= HeapAlloc(GetProcessHeap(),
194 dwMaxValueNameLength
* sizeof(WCHAR
));
195 if (lpNameBuffer
== NULL
)
197 DPRINT1("Buffer allocation failed\n");
198 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
202 lpDataBuffer
= HeapAlloc(GetProcessHeap(),
205 if (lpDataBuffer
== NULL
)
207 DPRINT1("Buffer allocation failed\n");
208 HeapFree(GetProcessHeap(),
211 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
215 for (i
= 0; i
< dwValues
; i
++)
217 dwValueNameLength
= dwMaxValueNameLength
;
218 dwValueLength
= dwMaxValueLength
;
219 Error
= RegEnumValueW(hSrcKey
,
227 if (Error
!= ERROR_SUCCESS
)
229 DPRINT1("Error: %lu\n", Error
);
230 HeapFree(GetProcessHeap(),
233 HeapFree(GetProcessHeap(),
236 SetLastError((DWORD
)Error
);
240 Error
= RegSetValueExW(hDstKey
,
246 if (Error
!= ERROR_SUCCESS
)
248 DPRINT1("Error: %lu\n", Error
);
249 HeapFree(GetProcessHeap(),
252 HeapFree(GetProcessHeap(),
255 SetLastError((DWORD
)Error
);
260 HeapFree(GetProcessHeap(),
264 HeapFree(GetProcessHeap(),
269 DPRINT("CopyKey() done \n");
277 CreateUserHive(LPCWSTR lpKeyName
,
278 LPCWSTR lpProfilePath
)
280 HKEY hDefaultKey
= NULL
;
281 HKEY hUserKey
= NULL
;
285 DPRINT("CreateUserHive(%S) called\n", lpKeyName
);
287 Error
= RegOpenKeyExW(HKEY_USERS
,
292 if (Error
!= ERROR_SUCCESS
)
294 SetLastError((DWORD
)Error
);
298 Error
= RegOpenKeyExW(HKEY_USERS
,
303 if (Error
!= ERROR_SUCCESS
)
305 SetLastError((DWORD
)Error
);
309 if (!CopyKey(hUserKey
, hDefaultKey
))
314 if (!UpdateUsersShellFolderSettings(lpProfilePath
,
320 RegFlushKey(hUserKey
);
324 if (hUserKey
!= NULL
)
325 RegCloseKey (hUserKey
);
327 if (hDefaultKey
!= NULL
)
328 RegCloseKey (hDefaultKey
);