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 DPRINT("dwSubKeys %lu\n", dwSubKeys
);
93 DPRINT("dwMaxSubKeyNameLength %lu\n", dwMaxSubKeyNameLength
);
94 DPRINT("dwValues %lu\n", dwValues
);
95 DPRINT("dwMaxValueNameLength %lu\n", dwMaxValueNameLength
);
96 DPRINT("dwMaxValueLength %lu\n", dwMaxValueLength
);
101 lpNameBuffer
= HeapAlloc(GetProcessHeap(),
103 dwMaxSubKeyNameLength
* sizeof(WCHAR
));
104 if (lpNameBuffer
== NULL
)
106 DPRINT1("Buffer allocation failed\n");
107 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
111 for (i
= 0; i
< dwSubKeys
; i
++)
113 dwSubKeyNameLength
= dwMaxSubKeyNameLength
;
114 Error
= RegEnumKeyExW(hSrcKey
,
122 if (Error
!= ERROR_SUCCESS
)
124 DPRINT1("Subkey enumeration failed (Error %lu)\n", Error
);
125 HeapFree(GetProcessHeap(),
128 SetLastError((DWORD
)Error
);
132 Error
= RegCreateKeyExW(hDstKey
,
136 REG_OPTION_NON_VOLATILE
,
141 if (Error
!= ERROR_SUCCESS
)
143 DPRINT1("Subkey creation failed (Error %lu)\n", Error
);
144 HeapFree(GetProcessHeap(),
147 SetLastError((DWORD
)Error
);
151 Error
= RegOpenKeyExW(hSrcKey
,
156 if (Error
!= ERROR_SUCCESS
)
158 DPRINT1("Error: %lu\n", Error
);
159 RegCloseKey(hDstSubKey
);
160 HeapFree(GetProcessHeap(),
163 SetLastError((DWORD
)Error
);
167 if (!CopyKey(hDstSubKey
,
170 DPRINT1("Error: %lu\n", GetLastError());
171 RegCloseKey (hSrcSubKey
);
172 RegCloseKey (hDstSubKey
);
173 HeapFree(GetProcessHeap(),
179 RegCloseKey(hSrcSubKey
);
180 RegCloseKey(hDstSubKey
);
183 HeapFree(GetProcessHeap(),
191 lpNameBuffer
= HeapAlloc(GetProcessHeap(),
193 dwMaxValueNameLength
* sizeof(WCHAR
));
194 if (lpNameBuffer
== NULL
)
196 DPRINT1("Buffer allocation failed\n");
197 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
201 lpDataBuffer
= HeapAlloc(GetProcessHeap(),
204 if (lpDataBuffer
== NULL
)
206 DPRINT1("Buffer allocation failed\n");
207 HeapFree(GetProcessHeap(),
210 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
214 for (i
= 0; i
< dwValues
; i
++)
216 dwValueNameLength
= dwMaxValueNameLength
;
217 dwValueLength
= dwMaxValueLength
;
218 Error
= RegEnumValueW(hSrcKey
,
226 if (Error
!= ERROR_SUCCESS
)
228 DPRINT1("Error: %lu\n", Error
);
229 HeapFree(GetProcessHeap(),
232 HeapFree(GetProcessHeap(),
235 SetLastError((DWORD
)Error
);
239 Error
= RegSetValueExW(hDstKey
,
245 if (Error
!= ERROR_SUCCESS
)
247 DPRINT1("Error: %lu\n", Error
);
248 HeapFree(GetProcessHeap(),
251 HeapFree(GetProcessHeap(),
254 SetLastError((DWORD
)Error
);
259 HeapFree(GetProcessHeap(),
263 HeapFree(GetProcessHeap(),
268 DPRINT("CopyKey() done \n");
276 CreateUserHive(LPCWSTR lpKeyName
,
277 LPCWSTR lpProfilePath
)
279 HKEY hDefaultKey
= NULL
;
280 HKEY hUserKey
= NULL
;
284 DPRINT("CreateUserHive(%S) called\n", lpKeyName
);
286 Error
= RegOpenKeyExW(HKEY_USERS
,
291 if (Error
!= ERROR_SUCCESS
)
293 SetLastError((DWORD
)Error
);
297 Error
= RegOpenKeyExW(HKEY_USERS
,
302 if (Error
!= ERROR_SUCCESS
)
304 SetLastError((DWORD
)Error
);
308 if (!CopyKey(hUserKey
, hDefaultKey
))
313 if (!UpdateUsersShellFolderSettings(lpProfilePath
,
319 RegFlushKey(hUserKey
);
323 if (hUserKey
!= NULL
)
324 RegCloseKey (hUserKey
);
326 if (hDefaultKey
!= NULL
)
327 RegCloseKey (hDefaultKey
);