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
31 /* FUNCTIONS ***************************************************************/
34 CopyKey (HKEY hDstKey
,
41 DWORD dwMaxSubKeyNameLength
;
42 DWORD dwSubKeyNameLength
;
43 DWORD dwMaxValueNameLength
;
44 DWORD dwValueNameLength
;
45 DWORD dwMaxValueLength
;
54 DPRINT ("CopyKey() called \n");
56 if (RegQueryInfoKey (hSrcKey
,
61 &dwMaxSubKeyNameLength
,
64 &dwMaxValueNameLength
,
69 DPRINT1 ("RegQueryInfoKey() failed (Error %lu)\n", GetLastError ());
73 DPRINT ("dwSubKeys %lu\n", dwSubKeys
);
74 DPRINT ("dwMaxSubKeyNameLength %lu\n", dwMaxSubKeyNameLength
);
75 DPRINT ("dwValues %lu\n", dwValues
);
76 DPRINT ("dwMaxValueNameLength %lu\n", dwMaxValueNameLength
);
77 DPRINT ("dwMaxValueLength %lu\n", dwMaxValueLength
);
82 lpNameBuffer
= HeapAlloc (GetProcessHeap (),
84 dwMaxSubKeyNameLength
* sizeof(WCHAR
));
85 if (lpNameBuffer
== NULL
)
87 DPRINT1("Buffer allocation failed\n");
91 for (i
= 0; i
< dwSubKeys
; i
++)
93 dwSubKeyNameLength
= dwMaxSubKeyNameLength
;
94 if (RegEnumKeyExW (hSrcKey
,
103 DPRINT1 ("Subkey enumeration failed (Error %lu)\n", GetLastError());
104 HeapFree (GetProcessHeap (),
110 if (RegCreateKeyExW (hDstKey
,
114 REG_OPTION_NON_VOLATILE
,
120 DPRINT1 ("Subkey creation failed (Error %lu)\n", GetLastError());
121 HeapFree (GetProcessHeap (),
127 if (RegOpenKeyExW (hSrcKey
,
133 DPRINT1 ("Error: %lu\n", GetLastError());
134 RegCloseKey (hDstSubKey
);
135 HeapFree (GetProcessHeap (),
141 if (!CopyKey (hDstSubKey
,
144 DPRINT1 ("Error: %lu\n", GetLastError());
145 RegCloseKey (hSrcSubKey
);
146 RegCloseKey (hDstSubKey
);
147 HeapFree (GetProcessHeap (),
153 RegCloseKey (hSrcSubKey
);
154 RegCloseKey (hDstSubKey
);
157 HeapFree (GetProcessHeap (),
165 lpNameBuffer
= HeapAlloc (GetProcessHeap (),
167 dwMaxValueNameLength
* sizeof(WCHAR
));
168 if (lpNameBuffer
== NULL
)
170 DPRINT1 ("Buffer allocation failed\n");
174 lpDataBuffer
= HeapAlloc (GetProcessHeap (),
177 if (lpDataBuffer
== NULL
)
179 DPRINT1 ("Buffer allocation failed\n");
180 HeapFree (GetProcessHeap (),
186 for (i
= 0; i
< dwValues
; i
++)
188 dwValueNameLength
= dwMaxValueNameLength
;
189 dwValueLength
= dwMaxValueLength
;
190 if (RegEnumValueW (hSrcKey
,
199 DPRINT1("Error: %lu\n", GetLastError());
200 HeapFree (GetProcessHeap (),
203 HeapFree (GetProcessHeap (),
209 if (RegSetValueExW (hDstKey
,
216 DPRINT1("Error: %lu\n", GetLastError());
217 HeapFree (GetProcessHeap (),
220 HeapFree (GetProcessHeap (),
227 HeapFree (GetProcessHeap (),
231 HeapFree (GetProcessHeap (),
236 DPRINT ("CopyKey() done \n");
243 CreateUserHive (LPCWSTR lpKeyName
,
244 LPCWSTR lpProfilePath
)
249 DPRINT ("CreateUserHive(%S) called\n", lpKeyName
);
251 if (RegOpenKeyExW (HKEY_USERS
,
257 DPRINT1 ("Error: %lu\n", GetLastError());
261 if (RegOpenKeyExW (HKEY_USERS
,
267 DPRINT1 ("Error: %lu\n", GetLastError());
268 RegCloseKey (hDefaultKey
);
272 if (!CopyKey(hUserKey
, hDefaultKey
))
274 DPRINT1 ("Error: %lu\n", GetLastError());
275 RegCloseKey (hUserKey
);
276 RegCloseKey (hDefaultKey
);
280 if (!UpdateUsersShellFolderSettings(lpProfilePath
,
283 DPRINT1("Error: %lu\n", GetLastError());
284 RegCloseKey (hUserKey
);
285 RegCloseKey (hDefaultKey
);
289 RegFlushKey (hUserKey
);
291 RegCloseKey (hUserKey
);
292 RegCloseKey (hDefaultKey
);
294 DPRINT ("CreateUserHive() done\n");