Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenregistry.c
Go to the documentation of this file.
00001 /* 00002 * ReactOS kernel 00003 * Copyright (C) 2004 ReactOS Team 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 /* $Id: registry.c 43790 2009-10-27 10:34:16Z dgorbachev $ 00020 * 00021 * COPYRIGHT: See COPYING in the top level directory 00022 * PROJECT: ReactOS system libraries 00023 * FILE: lib/userenv/registry.c 00024 * PURPOSE: User profile code 00025 * PROGRAMMER: Eric Kohl 00026 */ 00027 00028 #include <precomp.h> 00029 00030 #define NDEBUG 00031 #include <debug.h> 00032 00033 00034 /* FUNCTIONS ***************************************************************/ 00035 00036 static BOOL 00037 CopyKey (HKEY hDstKey, 00038 HKEY hSrcKey) 00039 { 00040 LONG Error; 00041 00042 #if (_WIN32_WINNT >= 0x0600) 00043 Error = RegCopyTreeW(hSrcKey, 00044 NULL, 00045 hDstKey); 00046 if (Error != ERROR_SUCCESS) 00047 { 00048 SetLastError((DWORD)Error); 00049 return FALSE; 00050 } 00051 00052 return TRUE; 00053 00054 #else 00055 FILETIME LastWrite; 00056 DWORD dwSubKeys; 00057 DWORD dwValues; 00058 DWORD dwType; 00059 DWORD dwMaxSubKeyNameLength; 00060 DWORD dwSubKeyNameLength; 00061 DWORD dwMaxValueNameLength; 00062 DWORD dwValueNameLength; 00063 DWORD dwMaxValueLength; 00064 DWORD dwValueLength; 00065 DWORD dwDisposition; 00066 DWORD i; 00067 LPWSTR lpNameBuffer; 00068 LPBYTE lpDataBuffer; 00069 HKEY hDstSubKey; 00070 HKEY hSrcSubKey; 00071 00072 DPRINT ("CopyKey() called \n"); 00073 00074 Error = RegQueryInfoKey (hSrcKey, 00075 NULL, 00076 NULL, 00077 NULL, 00078 &dwSubKeys, 00079 &dwMaxSubKeyNameLength, 00080 NULL, 00081 &dwValues, 00082 &dwMaxValueNameLength, 00083 &dwMaxValueLength, 00084 NULL, 00085 NULL); 00086 if (Error != ERROR_SUCCESS) 00087 { 00088 DPRINT1 ("RegQueryInfoKey() failed (Error %lu)\n", Error); 00089 SetLastError((DWORD)Error); 00090 return FALSE; 00091 } 00092 00093 DPRINT ("dwSubKeys %lu\n", dwSubKeys); 00094 DPRINT ("dwMaxSubKeyNameLength %lu\n", dwMaxSubKeyNameLength); 00095 DPRINT ("dwValues %lu\n", dwValues); 00096 DPRINT ("dwMaxValueNameLength %lu\n", dwMaxValueNameLength); 00097 DPRINT ("dwMaxValueLength %lu\n", dwMaxValueLength); 00098 00099 /* Copy subkeys */ 00100 if (dwSubKeys != 0) 00101 { 00102 lpNameBuffer = HeapAlloc (GetProcessHeap (), 00103 0, 00104 dwMaxSubKeyNameLength * sizeof(WCHAR)); 00105 if (lpNameBuffer == NULL) 00106 { 00107 DPRINT1("Buffer allocation failed\n"); 00108 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 00109 return FALSE; 00110 } 00111 00112 for (i = 0; i < dwSubKeys; i++) 00113 { 00114 dwSubKeyNameLength = dwMaxSubKeyNameLength; 00115 Error = RegEnumKeyExW (hSrcKey, 00116 i, 00117 lpNameBuffer, 00118 &dwSubKeyNameLength, 00119 NULL, 00120 NULL, 00121 NULL, 00122 &LastWrite); 00123 if (Error != ERROR_SUCCESS) 00124 { 00125 DPRINT1 ("Subkey enumeration failed (Error %lu)\n", Error); 00126 HeapFree (GetProcessHeap (), 00127 0, 00128 lpNameBuffer); 00129 SetLastError((DWORD)Error); 00130 return FALSE; 00131 } 00132 00133 Error = RegCreateKeyExW (hDstKey, 00134 lpNameBuffer, 00135 0, 00136 NULL, 00137 REG_OPTION_NON_VOLATILE, 00138 KEY_WRITE, 00139 NULL, 00140 &hDstSubKey, 00141 &dwDisposition); 00142 if (Error != ERROR_SUCCESS) 00143 { 00144 DPRINT1 ("Subkey creation failed (Error %lu)\n", Error); 00145 HeapFree (GetProcessHeap (), 00146 0, 00147 lpNameBuffer); 00148 SetLastError((DWORD)Error); 00149 return FALSE; 00150 } 00151 00152 Error = RegOpenKeyExW (hSrcKey, 00153 lpNameBuffer, 00154 0, 00155 KEY_READ, 00156 &hSrcSubKey); 00157 if (Error != ERROR_SUCCESS) 00158 { 00159 DPRINT1 ("Error: %lu\n", Error); 00160 RegCloseKey (hDstSubKey); 00161 HeapFree (GetProcessHeap (), 00162 0, 00163 lpNameBuffer); 00164 SetLastError((DWORD)Error); 00165 return FALSE; 00166 } 00167 00168 if (!CopyKey (hDstSubKey, 00169 hSrcSubKey)) 00170 { 00171 DPRINT1 ("Error: %lu\n", GetLastError()); 00172 RegCloseKey (hSrcSubKey); 00173 RegCloseKey (hDstSubKey); 00174 HeapFree (GetProcessHeap (), 00175 0, 00176 lpNameBuffer); 00177 return FALSE; 00178 } 00179 00180 RegCloseKey (hSrcSubKey); 00181 RegCloseKey (hDstSubKey); 00182 } 00183 00184 HeapFree (GetProcessHeap (), 00185 0, 00186 lpNameBuffer); 00187 } 00188 00189 /* Copy values */ 00190 if (dwValues != 0) 00191 { 00192 lpNameBuffer = HeapAlloc (GetProcessHeap (), 00193 0, 00194 dwMaxValueNameLength * sizeof(WCHAR)); 00195 if (lpNameBuffer == NULL) 00196 { 00197 DPRINT1 ("Buffer allocation failed\n"); 00198 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 00199 return FALSE; 00200 } 00201 00202 lpDataBuffer = HeapAlloc (GetProcessHeap (), 00203 0, 00204 dwMaxValueLength); 00205 if (lpDataBuffer == NULL) 00206 { 00207 DPRINT1 ("Buffer allocation failed\n"); 00208 HeapFree (GetProcessHeap (), 00209 0, 00210 lpNameBuffer); 00211 SetLastError(ERROR_NOT_ENOUGH_MEMORY); 00212 return FALSE; 00213 } 00214 00215 for (i = 0; i < dwValues; i++) 00216 { 00217 dwValueNameLength = dwMaxValueNameLength; 00218 dwValueLength = dwMaxValueLength; 00219 Error = RegEnumValueW (hSrcKey, 00220 i, 00221 lpNameBuffer, 00222 &dwValueNameLength, 00223 NULL, 00224 &dwType, 00225 lpDataBuffer, 00226 &dwValueLength); 00227 if (Error != ERROR_SUCCESS) 00228 { 00229 DPRINT1("Error: %lu\n", Error); 00230 HeapFree (GetProcessHeap (), 00231 0, 00232 lpDataBuffer); 00233 HeapFree (GetProcessHeap (), 00234 0, 00235 lpNameBuffer); 00236 SetLastError((DWORD)Error); 00237 return FALSE; 00238 } 00239 00240 Error = RegSetValueExW (hDstKey, 00241 lpNameBuffer, 00242 0, 00243 dwType, 00244 lpDataBuffer, 00245 dwValueLength); 00246 if (Error != ERROR_SUCCESS) 00247 { 00248 DPRINT1("Error: %lu\n", Error); 00249 HeapFree (GetProcessHeap (), 00250 0, 00251 lpDataBuffer); 00252 HeapFree (GetProcessHeap (), 00253 0, 00254 lpNameBuffer); 00255 SetLastError((DWORD)Error); 00256 return FALSE; 00257 } 00258 } 00259 00260 HeapFree (GetProcessHeap (), 00261 0, 00262 lpDataBuffer); 00263 00264 HeapFree (GetProcessHeap (), 00265 0, 00266 lpNameBuffer); 00267 } 00268 00269 DPRINT ("CopyKey() done \n"); 00270 00271 return TRUE; 00272 #endif 00273 } 00274 00275 00276 BOOL 00277 CreateUserHive (LPCWSTR lpKeyName, 00278 LPCWSTR lpProfilePath) 00279 { 00280 HKEY hDefaultKey = NULL; 00281 HKEY hUserKey = NULL; 00282 LONG Error; 00283 BOOL Ret = FALSE; 00284 00285 DPRINT ("CreateUserHive(%S) called\n", lpKeyName); 00286 00287 Error = RegOpenKeyExW (HKEY_USERS, 00288 L".Default", 00289 0, 00290 KEY_READ, 00291 &hDefaultKey); 00292 if (Error != ERROR_SUCCESS) 00293 { 00294 SetLastError((DWORD)Error); 00295 goto Cleanup; 00296 } 00297 00298 Error = RegOpenKeyExW (HKEY_USERS, 00299 lpKeyName, 00300 0, 00301 KEY_ALL_ACCESS, 00302 &hUserKey); 00303 if (Error != ERROR_SUCCESS) 00304 { 00305 SetLastError((DWORD)Error); 00306 goto Cleanup; 00307 } 00308 00309 if (!CopyKey(hUserKey, hDefaultKey)) 00310 { 00311 goto Cleanup; 00312 } 00313 00314 if (!UpdateUsersShellFolderSettings(lpProfilePath, 00315 hUserKey)) 00316 { 00317 goto Cleanup; 00318 } 00319 00320 RegFlushKey (hUserKey); 00321 Ret = TRUE; 00322 00323 Cleanup: 00324 if (hUserKey != NULL) 00325 RegCloseKey (hUserKey); 00326 00327 if (hDefaultKey != NULL) 00328 RegCloseKey (hDefaultKey); 00329 00330 return Ret; 00331 } 00332 00333 /* EOF */ Generated on Sun May 27 2012 04:17:08 for ReactOS by
1.7.6.1
|