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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS system libraries
23 * FILE: lib/userenv/registry.c
24 * PURPOSE: User profile code
25 * PROGRAMMER: Eric Kohl
34 /* FUNCTIONS ***************************************************************/
37 CopyKey (HKEY hDstKey
,
44 DWORD dwMaxSubKeyNameLength
;
45 DWORD dwSubKeyNameLength
;
46 DWORD dwMaxValueNameLength
;
47 DWORD dwValueNameLength
;
48 DWORD dwMaxValueLength
;
57 DPRINT ("CopyKey() called \n");
59 if (RegQueryInfoKey (hSrcKey
,
64 &dwMaxSubKeyNameLength
,
67 &dwMaxValueNameLength
,
72 DPRINT1 ("RegQueryInfoKey() failed (Error %lu)\n", GetLastError ());
76 DPRINT ("dwSubKeys %lu\n", dwSubKeys
);
77 DPRINT ("dwMaxSubKeyNameLength %lu\n", dwMaxSubKeyNameLength
);
78 DPRINT ("dwValues %lu\n", dwValues
);
79 DPRINT ("dwMaxValueNameLength %lu\n", dwMaxValueNameLength
);
80 DPRINT ("dwMaxValueLength %lu\n", dwMaxValueLength
);
85 lpNameBuffer
= HeapAlloc (GetProcessHeap (),
87 dwMaxSubKeyNameLength
* sizeof(WCHAR
));
88 if (lpNameBuffer
== NULL
)
90 DPRINT1("Buffer allocation failed\n");
94 for (i
= 0; i
< dwSubKeys
; i
++)
96 dwSubKeyNameLength
= dwMaxSubKeyNameLength
;
97 if (RegEnumKeyExW (hSrcKey
,
106 DPRINT1 ("Subkey enumeration failed (Error %lu)\n", GetLastError());
107 HeapFree (GetProcessHeap (),
113 if (RegCreateKeyExW (hDstKey
,
117 REG_OPTION_NON_VOLATILE
,
123 DPRINT1 ("Subkey creation failed (Error %lu)\n", GetLastError());
124 HeapFree (GetProcessHeap (),
130 if (RegOpenKeyExW (hSrcKey
,
136 DPRINT1 ("Error: %lu\n", GetLastError());
137 RegCloseKey (hDstSubKey
);
138 HeapFree (GetProcessHeap (),
144 if (!CopyKey (hDstSubKey
,
147 DPRINT1 ("Error: %lu\n", GetLastError());
148 RegCloseKey (hSrcSubKey
);
149 RegCloseKey (hDstSubKey
);
150 HeapFree (GetProcessHeap (),
156 RegCloseKey (hSrcSubKey
);
157 RegCloseKey (hDstSubKey
);
160 HeapFree (GetProcessHeap (),
168 lpNameBuffer
= HeapAlloc (GetProcessHeap (),
170 dwMaxValueNameLength
* sizeof(WCHAR
));
171 if (lpNameBuffer
== NULL
)
173 DPRINT1 ("Buffer allocation failed\n");
177 lpDataBuffer
= HeapAlloc (GetProcessHeap (),
180 if (lpDataBuffer
== NULL
)
182 DPRINT1 ("Buffer allocation failed\n");
183 HeapFree (GetProcessHeap (),
189 for (i
= 0; i
< dwValues
; i
++)
191 dwValueNameLength
= dwMaxValueNameLength
;
192 dwValueLength
= dwMaxValueLength
;
193 if (RegEnumValueW (hSrcKey
,
202 DPRINT1("Error: %lu\n", GetLastError());
203 HeapFree (GetProcessHeap (),
206 HeapFree (GetProcessHeap (),
212 if (RegSetValueExW (hDstKey
,
219 DPRINT1("Error: %lu\n", GetLastError());
220 HeapFree (GetProcessHeap (),
223 HeapFree (GetProcessHeap (),
230 HeapFree (GetProcessHeap (),
234 HeapFree (GetProcessHeap (),
239 DPRINT ("CopyKey() done \n");
246 CreateUserHive (LPCWSTR lpKeyName
,
247 LPCWSTR lpProfilePath
)
252 DPRINT ("CreateUserHive(%S) called\n", lpKeyName
);
254 if (RegOpenKeyExW (HKEY_USERS
,
260 DPRINT1 ("Error: %lu\n", GetLastError());
264 if (RegOpenKeyExW (HKEY_USERS
,
270 DPRINT1 ("Error: %lu\n", GetLastError());
271 RegCloseKey (hDefaultKey
);
275 if (!CopyKey(hUserKey
, hDefaultKey
))
277 DPRINT1 ("Error: %lu\n", GetLastError());
278 RegCloseKey (hUserKey
);
279 RegCloseKey (hDefaultKey
);
283 if (!UpdateUsersShellFolderSettings(lpProfilePath
,
286 DPRINT1("Error: %lu\n", GetLastError());
287 RegCloseKey (hUserKey
);
288 RegCloseKey (hDefaultKey
);
292 RegFlushKey (hUserKey
);
294 RegCloseKey (hUserKey
);
295 RegCloseKey (hDefaultKey
);
297 DPRINT ("CreateUserHive() done\n");