xref: /reactos/dll/win32/userenv/registry.c (revision 299e4305)
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 2004 ReactOS Team
4  *
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.
9  *
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.
14  *
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.
18  */
19 /*
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
25  */
26 
27 #include "precomp.h"
28 
29 #define NDEBUG
30 #include <debug.h>
31 
32 LSTATUS WINAPI RegCopyTreeW(_In_ HKEY, _In_opt_ LPCWSTR, _In_ HKEY);
33 
34 /* FUNCTIONS ***************************************************************/
35 
36 static
37 BOOL
38 CopyKey(HKEY hDstKey,
39         HKEY hSrcKey)
40 {
41     LONG Error;
42 
43     Error = RegCopyTreeW(hSrcKey,
44                          NULL,
45                          hDstKey);
46     if (Error != ERROR_SUCCESS)
47     {
48         SetLastError((DWORD)Error);
49         return FALSE;
50     }
51 
52     return TRUE;
53 }
54 
55 
56 BOOL
57 CreateUserHive(LPCWSTR lpKeyName,
58                LPCWSTR lpProfilePath)
59 {
60     HKEY hDefaultKey = NULL;
61     HKEY hUserKey = NULL;
62     LONG Error;
63     BOOL Ret = FALSE;
64 
65     DPRINT("CreateUserHive(%S) called\n", lpKeyName);
66 
67     Error = RegOpenKeyExW(HKEY_USERS,
68                           L".Default",
69                           0,
70                           KEY_READ,
71                           &hDefaultKey);
72     if (Error != ERROR_SUCCESS)
73     {
74         SetLastError((DWORD)Error);
75         goto Cleanup;
76     }
77 
78     Error = RegOpenKeyExW(HKEY_USERS,
79                           lpKeyName,
80                           0,
81                           KEY_ALL_ACCESS,
82                           &hUserKey);
83     if (Error != ERROR_SUCCESS)
84     {
85         SetLastError((DWORD)Error);
86         goto Cleanup;
87     }
88 
89     if (!CopyKey(hUserKey, hDefaultKey))
90     {
91         goto Cleanup;
92     }
93 
94     if (!UpdateUsersShellFolderSettings(lpProfilePath,
95                                         hUserKey))
96     {
97         goto Cleanup;
98     }
99 
100     RegFlushKey(hUserKey);
101     Ret = TRUE;
102 
103 Cleanup:
104     if (hUserKey != NULL)
105         RegCloseKey (hUserKey);
106 
107     if (hDefaultKey != NULL)
108         RegCloseKey (hDefaultKey);
109 
110     return Ret;
111 }
112 
113 /* EOF */
114