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
32 /* FUNCTIONS ***************************************************************/
41 #if (_WIN32_WINNT >= 0x0600)
42 Error
= RegCopyTreeW(hSrcKey
,
45 if (Error
!= ERROR_SUCCESS
)
47 SetLastError((DWORD
)Error
);
58 DWORD dwMaxSubKeyNameLength
;
59 DWORD dwSubKeyNameLength
;
60 DWORD dwMaxValueNameLength
;
61 DWORD dwValueNameLength
;
62 DWORD dwMaxValueLength
;
71 DPRINT ("CopyKey() called\n");
73 Error
= RegQueryInfoKey(hSrcKey
,
78 &dwMaxSubKeyNameLength
,
81 &dwMaxValueNameLength
,
85 if (Error
!= ERROR_SUCCESS
)
87 DPRINT1("RegQueryInfoKey() failed (Error %lu)\n", Error
);
88 SetLastError((DWORD
)Error
);
92 dwMaxSubKeyNameLength
++;
93 dwMaxValueNameLength
++;
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
);
104 lpNameBuffer
= HeapAlloc(GetProcessHeap(),
106 dwMaxSubKeyNameLength
* sizeof(WCHAR
));
107 if (lpNameBuffer
== NULL
)
109 DPRINT1("Buffer allocation failed\n");
110 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
114 for (i
= 0; i
< dwSubKeys
; i
++)
116 dwSubKeyNameLength
= dwMaxSubKeyNameLength
;
117 Error
= RegEnumKeyExW(hSrcKey
,
125 if (Error
!= ERROR_SUCCESS
)
127 DPRINT1("Subkey enumeration failed (Error %lu)\n", Error
);
128 HeapFree(GetProcessHeap(),
131 SetLastError((DWORD
)Error
);
135 Error
= RegCreateKeyExW(hDstKey
,
139 REG_OPTION_NON_VOLATILE
,
144 if (Error
!= ERROR_SUCCESS
)
146 DPRINT1("Subkey creation failed (Error %lu)\n", Error
);
147 HeapFree(GetProcessHeap(),
150 SetLastError((DWORD
)Error
);
154 Error
= RegOpenKeyExW(hSrcKey
,
159 if (Error
!= ERROR_SUCCESS
)
161 DPRINT1("Error: %lu\n", Error
);
162 RegCloseKey(hDstSubKey
);
163 HeapFree(GetProcessHeap(),
166 SetLastError((DWORD
)Error
);
170 if (!CopyKey(hDstSubKey
,
173 DPRINT1("Error: %lu\n", GetLastError());
174 RegCloseKey (hSrcSubKey
);
175 RegCloseKey (hDstSubKey
);
176 HeapFree(GetProcessHeap(),
182 RegCloseKey(hSrcSubKey
);
183 RegCloseKey(hDstSubKey
);
186 HeapFree(GetProcessHeap(),
194 lpNameBuffer
= HeapAlloc(GetProcessHeap(),
196 dwMaxValueNameLength
* sizeof(WCHAR
));
197 if (lpNameBuffer
== NULL
)
199 DPRINT1("Buffer allocation failed\n");
200 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
204 lpDataBuffer
= HeapAlloc(GetProcessHeap(),
207 if (lpDataBuffer
== NULL
)
209 DPRINT1("Buffer allocation failed\n");
210 HeapFree(GetProcessHeap(),
213 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
217 for (i
= 0; i
< dwValues
; i
++)
219 dwValueNameLength
= dwMaxValueNameLength
;
220 dwValueLength
= dwMaxValueLength
;
221 Error
= RegEnumValueW(hSrcKey
,
229 if (Error
!= ERROR_SUCCESS
)
231 DPRINT1("Error: %lu\n", Error
);
232 HeapFree(GetProcessHeap(),
235 HeapFree(GetProcessHeap(),
238 SetLastError((DWORD
)Error
);
242 Error
= RegSetValueExW(hDstKey
,
248 if (Error
!= ERROR_SUCCESS
)
250 DPRINT1("Error: %lu\n", Error
);
251 HeapFree(GetProcessHeap(),
254 HeapFree(GetProcessHeap(),
257 SetLastError((DWORD
)Error
);
262 HeapFree(GetProcessHeap(),
266 HeapFree(GetProcessHeap(),
271 DPRINT("CopyKey() done\n");
279 CreateUserHive(LPCWSTR lpKeyName
,
280 LPCWSTR lpProfilePath
)
282 HKEY hDefaultKey
= NULL
;
283 HKEY hUserKey
= NULL
;
287 DPRINT("CreateUserHive(%S) called\n", lpKeyName
);
289 Error
= RegOpenKeyExW(HKEY_USERS
,
294 if (Error
!= ERROR_SUCCESS
)
296 SetLastError((DWORD
)Error
);
300 Error
= RegOpenKeyExW(HKEY_USERS
,
305 if (Error
!= ERROR_SUCCESS
)
307 SetLastError((DWORD
)Error
);
311 if (!CopyKey(hUserKey
, hDefaultKey
))
316 if (!UpdateUsersShellFolderSettings(lpProfilePath
,
322 RegFlushKey(hUserKey
);
326 if (hUserKey
!= NULL
)
327 RegCloseKey (hUserKey
);
329 if (hDefaultKey
!= NULL
)
330 RegCloseKey (hDefaultKey
);