Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensetup.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: setup.c 47106 2010-05-05 22:30:14Z ekohl $ 00020 * 00021 * COPYRIGHT: See COPYING in the top level directory 00022 * PROJECT: ReactOS system libraries 00023 * FILE: lib/userenv/setup.c 00024 * PURPOSE: Profile setup functions 00025 * PROGRAMMER: Eric Kohl 00026 */ 00027 00028 #include <precomp.h> 00029 00030 #define NDEBUG 00031 #include <debug.h> 00032 00033 00034 typedef struct _FOLDERDATA 00035 { 00036 LPWSTR lpValueName; 00037 LPWSTR lpPath; 00038 UINT uId; 00039 BOOL bHidden; 00040 BOOL bShellFolder; 00041 BOOL bUserShellFolder; 00042 } FOLDERDATA, *PFOLDERDATA; 00043 00044 00045 static FOLDERDATA 00046 UserShellFolders[] = 00047 { 00048 {L"AppData", L"Application Data", IDS_APPDATA, TRUE, TRUE, TRUE}, 00049 {L"Desktop", L"Desktop", IDS_DESKTOP, FALSE, TRUE, TRUE}, 00050 {L"Favorites", L"Favorites", IDS_FAVORITES, FALSE, TRUE, TRUE}, 00051 {L"Personal", L"My Documents", IDS_MYDOCUMENTS, FALSE, TRUE, TRUE}, 00052 {L"My Pictures", L"My Documents\\My Pictures", IDS_MYPICTURES, FALSE, TRUE, TRUE}, 00053 {L"My Music", L"My Documents\\My Music", IDS_MYMUSIC, FALSE, TRUE, TRUE}, 00054 {L"My Video", L"My Documents\\My Videos", IDS_MYVIDEOS, FALSE, TRUE, TRUE}, 00055 {L"NetHood", L"NetHood", IDS_NETHOOD, TRUE, TRUE, TRUE}, 00056 {L"PrintHood", L"PrintHood", IDS_PRINTHOOD, TRUE, TRUE, TRUE}, 00057 {L"Recent", L"Recent", IDS_RECENT, TRUE, TRUE, TRUE}, 00058 {L"SendTo", L"SendTo", IDS_SENDTO, FALSE, TRUE, TRUE}, 00059 {L"Templates", L"Templates", IDS_TEMPLATES, FALSE, TRUE, TRUE}, 00060 {L"Start Menu", L"Start Menu", IDS_STARTMENU, FALSE, TRUE, TRUE}, 00061 {L"Programs", L"Start Menu\\Programs", IDS_PROGRAMS, FALSE, TRUE, TRUE}, 00062 {L"Startup", L"Start Menu\\Programs\\Startup", IDS_STARTUP, FALSE, TRUE, TRUE}, 00063 {L"Local Settings", L"Local Settings", IDS_LOCALSETTINGS, TRUE, TRUE, TRUE}, 00064 {L"Local AppData", L"Local Settings\\Application Data", IDS_LOCALAPPDATA, TRUE, TRUE, TRUE}, 00065 {L"Temp", L"Local Settings\\Temp", IDS_TEMP, FALSE, FALSE, FALSE}, 00066 {L"Cache", L"Local Settings\\Temporary Internet Files", IDS_CACHE, FALSE, TRUE, TRUE}, 00067 {L"History", L"Local Settings\\History", IDS_HISTORY, FALSE, TRUE, TRUE}, 00068 {L"Cookies", L"Cookies", IDS_COOKIES, FALSE, TRUE, TRUE}, 00069 {NULL, NULL, -1, FALSE, FALSE, FALSE} 00070 }; 00071 00072 00073 static FOLDERDATA 00074 CommonShellFolders[] = 00075 { 00076 {L"Common AppData", L"Application Data", IDS_APPDATA, TRUE, TRUE, TRUE}, 00077 {L"Common Desktop", L"Desktop", IDS_DESKTOP, FALSE, TRUE, TRUE}, 00078 {L"Common Favorites", L"Favorites", IDS_FAVORITES, FALSE, TRUE, TRUE}, 00079 {L"Common Start Menu", L"Start Menu", IDS_STARTMENU, FALSE, TRUE, TRUE}, 00080 {L"Common Programs", L"Start Menu\\Programs", IDS_PROGRAMS, FALSE, TRUE, TRUE}, 00081 {L"Common Administrative Tools", L"Start Menu\\Programs\\Administrative Tools", IDS_ADMINTOOLS, FALSE, TRUE, FALSE}, 00082 {L"Common Startup", L"Start Menu\\Programs\\Startup", IDS_STARTUP, FALSE, TRUE, TRUE}, 00083 {L"Common Templates", L"Templates", IDS_TEMPLATES, TRUE, TRUE, TRUE}, 00084 {L"Common Documents", L"My Documents", IDS_MYDOCUMENTS, FALSE, TRUE, TRUE}, 00085 {L"CommonPictures", L"My Documents\\My Pictures", IDS_MYPICTURES, FALSE, TRUE, TRUE}, 00086 {L"CommonMusic", L"My Documents\\My Music", IDS_MYMUSIC, FALSE, TRUE, TRUE}, 00087 {L"CommonVideo", L"My Documents\\My Videos", IDS_MYVIDEOS, FALSE, TRUE, TRUE}, 00088 {NULL, NULL, -1, FALSE, FALSE, FALSE} 00089 }; 00090 00091 00092 void 00093 DebugPrint(char* fmt,...) 00094 { 00095 char buffer[512]; 00096 va_list ap; 00097 00098 va_start(ap, fmt); 00099 vsprintf(buffer, fmt, ap); 00100 va_end(ap); 00101 00102 OutputDebugStringA(buffer); 00103 } 00104 00105 00106 BOOL 00107 WINAPI 00108 InitializeProfiles(VOID) 00109 { 00110 WCHAR szProfilesPath[MAX_PATH]; 00111 WCHAR szProfilePath[MAX_PATH]; 00112 WCHAR szCommonFilesDirPath[MAX_PATH]; 00113 WCHAR szBuffer[MAX_PATH]; 00114 DWORD dwLength; 00115 PFOLDERDATA lpFolderData; 00116 HKEY hKey; 00117 LONG Error; 00118 00119 DPRINT("InitializeProfiles()\n"); 00120 00121 /* Load profiles directory path */ 00122 if (!LoadStringW(hInstance, 00123 IDS_PROFILEPATH, 00124 szBuffer, 00125 MAX_PATH)) 00126 { 00127 DPRINT1("Error: %lu\n", GetLastError()); 00128 return FALSE; 00129 } 00130 00131 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00132 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", 00133 0, 00134 KEY_SET_VALUE, 00135 &hKey); 00136 if (Error != ERROR_SUCCESS) 00137 { 00138 DPRINT1("Error: %lu\n", Error); 00139 SetLastError((DWORD)Error); 00140 return FALSE; 00141 } 00142 00143 /* Expand it */ 00144 if (!ExpandEnvironmentStringsW(szBuffer, 00145 szProfilesPath, 00146 MAX_PATH)) 00147 { 00148 DPRINT1("Error: %lu\n", GetLastError()); 00149 RegCloseKey(hKey); 00150 return FALSE; 00151 } 00152 00153 /* Create profiles directory */ 00154 if (!CreateDirectoryW(szProfilesPath, NULL)) 00155 { 00156 if (GetLastError() != ERROR_ALREADY_EXISTS) 00157 { 00158 DPRINT1("Error: %lu\n", GetLastError()); 00159 RegCloseKey(hKey); 00160 return FALSE; 00161 } 00162 } 00163 00164 /* Store the profiles directory path in the registry */ 00165 dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR); 00166 Error = RegSetValueExW(hKey, 00167 L"ProfilesDirectory", 00168 0, 00169 REG_EXPAND_SZ, 00170 (LPBYTE)szBuffer, 00171 dwLength); 00172 if (Error != ERROR_SUCCESS) 00173 { 00174 DPRINT1("Error: %lu\n", Error); 00175 RegCloseKey(hKey); 00176 SetLastError((DWORD)Error); 00177 return FALSE; 00178 } 00179 00180 /* Set 'DefaultUserProfile' value */ 00181 wcscpy(szBuffer, L"Default User"); 00182 00183 /* Create Default User profile directory path */ 00184 wcscpy(szProfilePath, szProfilesPath); 00185 wcscat(szProfilePath, L"\\"); 00186 wcscat(szProfilePath, szBuffer); 00187 00188 /* Attempt default user directory creation */ 00189 if (!CreateDirectoryW (szProfilePath, NULL)) 00190 { 00191 if (GetLastError() != ERROR_ALREADY_EXISTS) 00192 { 00193 DPRINT1("Error: %lu\n", GetLastError()); 00194 RegCloseKey(hKey); 00195 return FALSE; 00196 } 00197 00198 /* Directory existed, let's try to append the postfix */ 00199 if (!AppendSystemPostfix(szBuffer, MAX_PATH)) 00200 { 00201 DPRINT1("AppendSystemPostfix() failed\n", GetLastError()); 00202 RegCloseKey(hKey); 00203 return FALSE; 00204 } 00205 00206 /* Create Default User profile directory path again */ 00207 wcscpy(szProfilePath, szProfilesPath); 00208 wcscat(szProfilePath, L"\\"); 00209 wcscat(szProfilePath, szBuffer); 00210 00211 /* Attempt creation again with appended postfix */ 00212 if (!CreateDirectoryW(szProfilePath, NULL)) 00213 { 00214 if (GetLastError() != ERROR_ALREADY_EXISTS) 00215 { 00216 DPRINT1("Error: %lu\n", GetLastError()); 00217 RegCloseKey(hKey); 00218 return FALSE; 00219 } 00220 } 00221 } 00222 00223 /* Store the default user profile path in the registry */ 00224 dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR); 00225 Error = RegSetValueExW(hKey, 00226 L"DefaultUserProfile", 00227 0, 00228 REG_SZ, 00229 (LPBYTE)szBuffer, 00230 dwLength); 00231 if (Error != ERROR_SUCCESS) 00232 { 00233 DPRINT1("Error: %lu\n", Error); 00234 RegCloseKey(hKey); 00235 SetLastError((DWORD)Error); 00236 return FALSE; 00237 } 00238 00239 RegCloseKey(hKey); 00240 00241 /* Set current user profile */ 00242 SetEnvironmentVariableW(L"USERPROFILE", szProfilePath); 00243 00244 /* Create 'Default User' subdirectories */ 00245 /* FIXME: Get these paths from the registry */ 00246 lpFolderData = &UserShellFolders[0]; 00247 while (lpFolderData->lpValueName != NULL) 00248 { 00249 wcscpy(szBuffer, szProfilePath); 00250 wcscat(szBuffer, L"\\"); 00251 00252 /* Append the folder name */ 00253 dwLength = wcslen(szBuffer); 00254 if (!LoadStringW(hInstance, 00255 lpFolderData->uId, 00256 &szBuffer[dwLength], 00257 MAX_PATH - dwLength)) 00258 { 00259 /* Use the default name instead */ 00260 wcscat(szBuffer, lpFolderData->lpPath); 00261 } 00262 00263 if (!CreateDirectoryW(szBuffer, NULL)) 00264 { 00265 if (GetLastError() != ERROR_ALREADY_EXISTS) 00266 { 00267 DPRINT1("Error: %lu\n", GetLastError()); 00268 return FALSE; 00269 } 00270 } 00271 00272 if (lpFolderData->bHidden == TRUE) 00273 { 00274 SetFileAttributesW(szBuffer, 00275 FILE_ATTRIBUTE_HIDDEN); 00276 } 00277 00278 lpFolderData++; 00279 } 00280 00281 /* Set default 'Shell Folders' values */ 00282 Error = RegOpenKeyExW(HKEY_USERS, 00283 L".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 00284 0, 00285 KEY_SET_VALUE, 00286 &hKey); 00287 if (Error != ERROR_SUCCESS) 00288 { 00289 DPRINT1("Error: %lu\n", Error); 00290 SetLastError((DWORD)Error); 00291 return FALSE; 00292 } 00293 00294 lpFolderData = &UserShellFolders[0]; 00295 while (lpFolderData->lpValueName != NULL) 00296 { 00297 if (lpFolderData->bShellFolder) 00298 { 00299 wcscpy(szBuffer, szProfilePath); 00300 wcscat(szBuffer, L"\\"); 00301 00302 /* Append the folder name */ 00303 dwLength = wcslen(szBuffer); 00304 if (!LoadStringW(hInstance, 00305 lpFolderData->uId, 00306 &szBuffer[dwLength], 00307 MAX_PATH - dwLength)) 00308 { 00309 /* Use the default name instead */ 00310 wcscat(szBuffer, lpFolderData->lpPath); 00311 } 00312 00313 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR); 00314 Error = RegSetValueExW(hKey, 00315 lpFolderData->lpValueName, 00316 0, 00317 REG_SZ, 00318 (LPBYTE)szBuffer, 00319 dwLength); 00320 if (Error != ERROR_SUCCESS) 00321 { 00322 DPRINT1("Error: %lu\n", Error); 00323 RegCloseKey(hKey); 00324 SetLastError((DWORD)Error); 00325 return FALSE; 00326 } 00327 } 00328 00329 lpFolderData++; 00330 } 00331 00332 /* Set 'Fonts' folder path */ 00333 GetWindowsDirectoryW(szBuffer, MAX_PATH); 00334 wcscat(szBuffer, L"\\fonts"); 00335 00336 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR); 00337 Error = RegSetValueExW(hKey, 00338 L"Fonts", 00339 0, 00340 REG_SZ, 00341 (LPBYTE)szBuffer, 00342 dwLength); 00343 if (Error != ERROR_SUCCESS) 00344 { 00345 DPRINT1("Error: %lu\n", Error); 00346 RegCloseKey(hKey); 00347 SetLastError((DWORD)Error); 00348 return FALSE; 00349 } 00350 00351 RegCloseKey(hKey); 00352 00353 /* Set default 'User Shell Folders' values */ 00354 Error = RegOpenKeyExW(HKEY_USERS, 00355 L".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", 00356 0, 00357 KEY_SET_VALUE, 00358 &hKey); 00359 if (Error != ERROR_SUCCESS) 00360 { 00361 DPRINT1("Error: %lu\n", Error); 00362 SetLastError((DWORD)Error); 00363 return FALSE; 00364 } 00365 00366 lpFolderData = &UserShellFolders[0]; 00367 while (lpFolderData->lpValueName != NULL) 00368 { 00369 if (lpFolderData->bUserShellFolder) 00370 { 00371 wcscpy(szBuffer, L"%USERPROFILE%\\"); 00372 00373 /* Append the folder name */ 00374 dwLength = wcslen(szBuffer); 00375 if (!LoadStringW(hInstance, 00376 lpFolderData->uId, 00377 &szBuffer[dwLength], 00378 MAX_PATH - dwLength)) 00379 { 00380 /* Use the default name instead */ 00381 wcscat(szBuffer, lpFolderData->lpPath); 00382 } 00383 00384 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR); 00385 Error = RegSetValueExW(hKey, 00386 lpFolderData->lpValueName, 00387 0, 00388 REG_EXPAND_SZ, 00389 (LPBYTE)szBuffer, 00390 dwLength); 00391 if (Error != ERROR_SUCCESS) 00392 { 00393 DPRINT1("Error: %lu\n", Error); 00394 RegCloseKey(hKey); 00395 SetLastError((DWORD)Error); 00396 return FALSE; 00397 } 00398 } 00399 00400 lpFolderData++; 00401 } 00402 00403 RegCloseKey(hKey); 00404 00405 /* Set 'AllUsersProfile' value */ 00406 wcscpy(szBuffer, L"All Users"); 00407 00408 /* Create 'All Users' profile directory path */ 00409 wcscpy(szProfilePath, szProfilesPath); 00410 wcscat(szProfilePath, L"\\"); 00411 wcscat(szProfilePath, szBuffer); 00412 00413 /* Attempt 'All Users' directory creation */ 00414 if (!CreateDirectoryW (szProfilePath, NULL)) 00415 { 00416 if (GetLastError() != ERROR_ALREADY_EXISTS) 00417 { 00418 DPRINT1("Error: %lu\n", GetLastError()); 00419 return FALSE; 00420 } 00421 00422 /* Directory existed, let's try to append the postfix */ 00423 if (!AppendSystemPostfix(szBuffer, MAX_PATH)) 00424 { 00425 DPRINT1("AppendSystemPostfix() failed\n", GetLastError()); 00426 return FALSE; 00427 } 00428 00429 /* Attempt again creation with appended postfix */ 00430 wcscpy(szProfilePath, szProfilesPath); 00431 wcscat(szProfilePath, L"\\"); 00432 wcscat(szProfilePath, szBuffer); 00433 00434 if (!CreateDirectoryW(szProfilePath, NULL)) 00435 { 00436 if (GetLastError() != ERROR_ALREADY_EXISTS) 00437 { 00438 DPRINT1("Error: %lu\n", GetLastError()); 00439 return FALSE; 00440 } 00441 } 00442 } 00443 00444 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00445 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", 00446 0, 00447 KEY_SET_VALUE, 00448 &hKey); 00449 if (Error != ERROR_SUCCESS) 00450 { 00451 DPRINT1("Error: %lu\n", Error); 00452 SetLastError((DWORD)Error); 00453 return FALSE; 00454 } 00455 00456 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR); 00457 Error = RegSetValueExW(hKey, 00458 L"AllUsersProfile", 00459 0, 00460 REG_SZ, 00461 (LPBYTE)szBuffer, 00462 dwLength); 00463 00464 RegCloseKey(hKey); 00465 00466 if (Error != ERROR_SUCCESS) 00467 { 00468 DPRINT1("Error: %lu\n", Error); 00469 SetLastError((DWORD)Error); 00470 return FALSE; 00471 } 00472 00473 /* Set 'All Users' profile */ 00474 SetEnvironmentVariableW(L"ALLUSERSPROFILE", szProfilePath); 00475 00476 /* Create 'All Users' subdirectories */ 00477 /* FIXME: Take these paths from the registry */ 00478 lpFolderData = &CommonShellFolders[0]; 00479 while (lpFolderData->lpValueName != NULL) 00480 { 00481 wcscpy(szBuffer, szProfilePath); 00482 wcscat(szBuffer, L"\\"); 00483 00484 /* Append the folder name */ 00485 dwLength = wcslen(szBuffer); 00486 if (!LoadStringW(hInstance, 00487 lpFolderData->uId, 00488 &szBuffer[dwLength], 00489 MAX_PATH - dwLength)) 00490 { 00491 /* Use the default name instead */ 00492 wcscat(szBuffer, lpFolderData->lpPath); 00493 } 00494 00495 if (!CreateDirectoryW(szBuffer, NULL)) 00496 { 00497 if (GetLastError() != ERROR_ALREADY_EXISTS) 00498 { 00499 DPRINT1("Error: %lu\n", GetLastError()); 00500 return FALSE; 00501 } 00502 } 00503 00504 if (lpFolderData->bHidden) 00505 { 00506 SetFileAttributesW(szBuffer, 00507 FILE_ATTRIBUTE_HIDDEN); 00508 } 00509 00510 lpFolderData++; 00511 } 00512 00513 /* Set common 'Shell Folders' values */ 00514 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00515 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 00516 0, 00517 KEY_SET_VALUE, 00518 &hKey); 00519 if (Error != ERROR_SUCCESS) 00520 { 00521 DPRINT1("Error: %lu\n", Error); 00522 SetLastError((DWORD)Error); 00523 return FALSE; 00524 } 00525 00526 lpFolderData = &CommonShellFolders[0]; 00527 while (lpFolderData->lpValueName != NULL) 00528 { 00529 if (lpFolderData->bShellFolder) 00530 { 00531 wcscpy(szBuffer, szProfilePath); 00532 wcscat(szBuffer, L"\\"); 00533 00534 /* Append the folder name */ 00535 dwLength = wcslen(szBuffer); 00536 if (!LoadStringW(hInstance, 00537 lpFolderData->uId, 00538 &szBuffer[dwLength], 00539 MAX_PATH - dwLength)) 00540 { 00541 /* Use the default name instead */ 00542 wcscat(szBuffer, lpFolderData->lpPath); 00543 } 00544 00545 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR); 00546 Error = RegSetValueExW(hKey, 00547 lpFolderData->lpValueName, 00548 0, 00549 REG_SZ, 00550 (LPBYTE)szBuffer, 00551 dwLength); 00552 if (Error != ERROR_SUCCESS) 00553 { 00554 DPRINT1("Error: %lu\n", Error); 00555 RegCloseKey(hKey); 00556 SetLastError((DWORD)Error); 00557 return FALSE; 00558 } 00559 } 00560 00561 lpFolderData++; 00562 } 00563 00564 RegCloseKey(hKey); 00565 00566 /* Set common 'User Shell Folders' values */ 00567 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00568 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", 00569 0, 00570 KEY_SET_VALUE, 00571 &hKey); 00572 if (Error != ERROR_SUCCESS) 00573 { 00574 DPRINT1("Error: %lu\n", Error); 00575 SetLastError((DWORD)Error); 00576 return FALSE; 00577 } 00578 00579 lpFolderData = &CommonShellFolders[0]; 00580 while (lpFolderData->lpValueName != NULL) 00581 { 00582 if (lpFolderData->bUserShellFolder) 00583 { 00584 wcscpy(szBuffer, L"%ALLUSERSPROFILE%\\"); 00585 00586 /* Append the folder name */ 00587 dwLength = wcslen(szBuffer); 00588 if (!LoadStringW(hInstance, 00589 lpFolderData->uId, 00590 &szBuffer[dwLength], 00591 MAX_PATH - dwLength)) 00592 { 00593 /* Use the default name instead */ 00594 wcscat(szBuffer, lpFolderData->lpPath); 00595 } 00596 00597 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR); 00598 Error = RegSetValueExW(hKey, 00599 lpFolderData->lpValueName, 00600 0, 00601 REG_EXPAND_SZ, 00602 (LPBYTE)szBuffer, 00603 dwLength); 00604 if (Error != ERROR_SUCCESS) 00605 { 00606 DPRINT1("Error: %lu\n", Error); 00607 RegCloseKey(hKey); 00608 SetLastError((DWORD)Error); 00609 return FALSE; 00610 } 00611 } 00612 00613 lpFolderData++; 00614 } 00615 00616 RegCloseKey(hKey); 00617 00618 /* Load 'Program Files' location */ 00619 if (!LoadStringW(hInstance, 00620 IDS_PROGRAMFILES, 00621 szBuffer, 00622 MAX_PATH)) 00623 { 00624 DPRINT1("Error: %lu\n", GetLastError()); 00625 return FALSE; 00626 } 00627 00628 if (!LoadStringW(hInstance, 00629 IDS_COMMONFILES, 00630 szCommonFilesDirPath, 00631 MAX_PATH)) 00632 { 00633 DPRINT1("Warning: %lu\n", GetLastError()); 00634 } 00635 00636 /* Expand it */ 00637 if (!ExpandEnvironmentStringsW(szBuffer, 00638 szProfilesPath, 00639 MAX_PATH)) 00640 { 00641 DPRINT1("Error: %lu\n", GetLastError()); 00642 return FALSE; 00643 } 00644 00645 wcscpy(szBuffer, szProfilesPath); 00646 wcscat(szBuffer, L"\\"); 00647 wcscat(szBuffer, szCommonFilesDirPath); 00648 00649 if (!ExpandEnvironmentStringsW(szBuffer, 00650 szCommonFilesDirPath, 00651 MAX_PATH)) 00652 { 00653 DPRINT1("Warning: %lu\n", GetLastError()); 00654 } 00655 00656 /* Store it */ 00657 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00658 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 00659 0, 00660 KEY_SET_VALUE, 00661 &hKey); 00662 if (Error != ERROR_SUCCESS) 00663 { 00664 DPRINT1("Error: %lu\n", Error); 00665 SetLastError((DWORD)Error); 00666 return FALSE; 00667 } 00668 00669 dwLength = (wcslen (szProfilesPath) + 1) * sizeof(WCHAR); 00670 Error = RegSetValueExW(hKey, 00671 L"ProgramFilesDir", 00672 0, 00673 REG_SZ, 00674 (LPBYTE)szProfilesPath, 00675 dwLength); 00676 if (Error != ERROR_SUCCESS) 00677 { 00678 DPRINT1("Error: %lu\n", Error); 00679 RegCloseKey(hKey); 00680 SetLastError((DWORD)Error); 00681 return FALSE; 00682 } 00683 00684 dwLength = (wcslen(szCommonFilesDirPath) + 1) * sizeof(WCHAR); 00685 Error = RegSetValueExW(hKey, 00686 L"CommonFilesDir", 00687 0, 00688 REG_SZ, 00689 (LPBYTE)szCommonFilesDirPath, 00690 dwLength); 00691 if (Error != ERROR_SUCCESS) 00692 { 00693 DPRINT1("Warning: %lu\n", Error); 00694 } 00695 00696 RegCloseKey (hKey); 00697 00698 /* Create directory */ 00699 if (!CreateDirectoryW(szProfilesPath, NULL)) 00700 { 00701 if (GetLastError () != ERROR_ALREADY_EXISTS) 00702 { 00703 DPRINT1("Error: %lu\n", GetLastError()); 00704 return FALSE; 00705 } 00706 } 00707 00708 /* Create directory */ 00709 if (!CreateDirectoryW(szCommonFilesDirPath, NULL)) 00710 { 00711 if (GetLastError () != ERROR_ALREADY_EXISTS) 00712 { 00713 DPRINT1("Warning: %lu\n", GetLastError()); 00714 } 00715 } 00716 00717 DPRINT("Success\n"); 00718 00719 return TRUE; 00720 } 00721 00722 00723 BOOL 00724 UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath, 00725 HKEY hUserKey) 00726 { 00727 WCHAR szBuffer[MAX_PATH]; 00728 DWORD dwLength; 00729 PFOLDERDATA lpFolderData; 00730 HKEY hFoldersKey; 00731 LONG Error; 00732 00733 DPRINT("UpdateUsersShellFolderSettings() called\n"); 00734 00735 DPRINT("User profile path: %S\n", lpUserProfilePath); 00736 00737 Error = RegOpenKeyExW(hUserKey, 00738 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 00739 0, 00740 KEY_SET_VALUE, 00741 &hFoldersKey); 00742 if (Error != ERROR_SUCCESS) 00743 { 00744 DPRINT1("Error: %lu\n", Error); 00745 SetLastError((DWORD)Error); 00746 return FALSE; 00747 } 00748 00749 lpFolderData = &UserShellFolders[0]; 00750 while (lpFolderData->lpValueName != NULL) 00751 { 00752 if (lpFolderData->bShellFolder) 00753 { 00754 wcscpy(szBuffer, lpUserProfilePath); 00755 wcscat(szBuffer, L"\\"); 00756 00757 /* Append the folder name */ 00758 dwLength = wcslen(szBuffer); 00759 if (!LoadStringW(hInstance, 00760 lpFolderData->uId, 00761 &szBuffer[dwLength], 00762 MAX_PATH - dwLength)) 00763 { 00764 /* Use the default name instead */ 00765 wcscat(szBuffer, lpFolderData->lpPath); 00766 } 00767 00768 DPRINT("%S: %S\n", lpFolderData->lpValueName, szBuffer); 00769 00770 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR); 00771 Error = RegSetValueExW(hFoldersKey, 00772 lpFolderData->lpValueName, 00773 0, 00774 REG_SZ, 00775 (LPBYTE)szBuffer, 00776 dwLength); 00777 if (Error != ERROR_SUCCESS) 00778 { 00779 DPRINT1("Error: %lu\n", Error); 00780 RegCloseKey(hFoldersKey); 00781 SetLastError((DWORD)Error); 00782 return FALSE; 00783 } 00784 } 00785 00786 lpFolderData++; 00787 } 00788 00789 RegCloseKey(hFoldersKey); 00790 00791 DPRINT("UpdateUsersShellFolderSettings() done\n"); 00792 00793 return TRUE; 00794 } 00795 00796 /* EOF */ Generated on Sat May 26 2012 04:16:41 for ReactOS by
1.7.6.1
|