24119d2b18cb1d676a6b8af11c47ebdf93281b30
[reactos.git] / reactos / dll / win32 / userenv / setup.c
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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS system libraries
23 * FILE: lib/userenv/setup.c
24 * PURPOSE: Profile setup functions
25 * PROGRAMMER: Eric Kohl
26 */
27
28 #include <precomp.h>
29
30 #define NDEBUG
31 #include <debug.h>
32
33
34 typedef struct _FOLDERDATA
35 {
36 LPWSTR lpValueName;
37 LPWSTR lpPath;
38 UINT uId;
39 BOOL bHidden;
40 BOOL bShellFolder;
41 BOOL bUserShellFolder;
42 } FOLDERDATA, *PFOLDERDATA;
43
44
45 static FOLDERDATA
46 UserShellFolders[] =
47 {
48 {L"AppData", L"Application Data", IDS_APPDATA, TRUE, TRUE, TRUE},
49 {L"Desktop", L"Desktop", IDS_DESKTOP, FALSE, TRUE, TRUE},
50 {L"Favorites", L"Favorites", IDS_FAVORITES, FALSE, TRUE, TRUE},
51 {L"Personal", L"My Documents", IDS_MYDOCUMENTS, FALSE, TRUE, TRUE},
52 {L"My Pictures", L"My Documents\\My Pictures", IDS_MYPICTURES, FALSE, TRUE, TRUE},
53 {L"My Music", L"My Documents\\My Music", IDS_MYMUSIC, FALSE, TRUE, TRUE},
54 {L"My Video", L"My Documents\\My Videos", IDS_MYVIDEOS, FALSE, TRUE, TRUE},
55 {L"NetHood", L"NetHood", IDS_NETHOOD, TRUE, TRUE, TRUE},
56 {L"PrintHood", L"PrintHood", IDS_PRINTHOOD, TRUE, TRUE, TRUE},
57 {L"Recent", L"Recent", IDS_RECENT, TRUE, TRUE, TRUE},
58 {L"SendTo", L"SendTo", IDS_SENDTO, FALSE, TRUE, TRUE},
59 {L"Templates", L"Templates", IDS_TEMPLATES, FALSE, TRUE, TRUE},
60 {L"Start Menu", L"Start Menu", IDS_STARTMENU, FALSE, TRUE, TRUE},
61 {L"Programs", L"Start Menu\\Programs", IDS_PROGRAMS, FALSE, TRUE, TRUE},
62 {L"Startup", L"Start Menu\\Programs\\Startup", IDS_STARTUP, FALSE, TRUE, TRUE},
63 {L"Local Settings", L"Local Settings", IDS_LOCALSETTINGS, TRUE, TRUE, TRUE},
64 {L"Local AppData", L"Local Settings\\Application Data", IDS_LOCALAPPDATA, TRUE, TRUE, TRUE},
65 {L"Temp", L"Local Settings\\Temp", IDS_TEMP, FALSE, FALSE, FALSE},
66 {L"Cache", L"Local Settings\\Temporary Internet Files", IDS_CACHE, FALSE, TRUE, TRUE},
67 {L"History", L"Local Settings\\History", IDS_HISTORY, FALSE, TRUE, TRUE},
68 {L"Cookies", L"Cookies", IDS_COOKIES, FALSE, TRUE, TRUE},
69 {NULL, NULL, -1, FALSE, FALSE, FALSE}
70 };
71
72
73 static FOLDERDATA
74 CommonShellFolders[] =
75 {
76 {L"Common AppData", L"Application Data", IDS_APPDATA, TRUE, TRUE, TRUE},
77 {L"Common Desktop", L"Desktop", IDS_DESKTOP, FALSE, TRUE, TRUE},
78 {L"Common Favorites", L"Favorites", IDS_FAVORITES, FALSE, TRUE, TRUE},
79 {L"Common Start Menu", L"Start Menu", IDS_STARTMENU, FALSE, TRUE, TRUE},
80 {L"Common Programs", L"Start Menu\\Programs", IDS_PROGRAMS, FALSE, TRUE, TRUE},
81 {L"Common Administrative Tools", L"Start Menu\\Programs\\Administrative Tools", IDS_ADMINTOOLS, FALSE, TRUE, FALSE},
82 {L"Common Startup", L"Start Menu\\Programs\\Startup", IDS_STARTUP, FALSE, TRUE, TRUE},
83 {L"Common Templates", L"Templates", IDS_TEMPLATES, TRUE, TRUE, TRUE},
84 {L"Common Documents", L"My Documents", IDS_MYDOCUMENTS, FALSE, TRUE, TRUE},
85 {L"CommonPictures", L"My Documents\\My Pictures", IDS_MYPICTURES, FALSE, TRUE, TRUE},
86 {L"CommonMusic", L"My Documents\\My Music", IDS_MYMUSIC, FALSE, TRUE, TRUE},
87 {L"CommonVideo", L"My Documents\\My Videos", IDS_MYVIDEOS, FALSE, TRUE, TRUE},
88 {NULL, NULL, -1, FALSE, FALSE, FALSE}
89 };
90
91
92 void
93 DebugPrint(char* fmt,...)
94 {
95 char buffer[512];
96 va_list ap;
97
98 va_start(ap, fmt);
99 vsprintf(buffer, fmt, ap);
100 va_end(ap);
101
102 OutputDebugStringA(buffer);
103 }
104
105
106 BOOL
107 WINAPI
108 InitializeProfiles(VOID)
109 {
110 WCHAR szProfilesPath[MAX_PATH];
111 WCHAR szProfilePath[MAX_PATH];
112 WCHAR szCommonFilesDirPath[MAX_PATH];
113 WCHAR szBuffer[MAX_PATH];
114 DWORD dwLength;
115 PFOLDERDATA lpFolderData;
116 HKEY hKey;
117 LONG Error;
118
119 DPRINT("InitializeProfiles()\n");
120
121 /* Load profiles directory path */
122 if (!LoadStringW(hInstance,
123 IDS_PROFILEPATH,
124 szBuffer,
125 MAX_PATH))
126 {
127 DPRINT1("Error: %lu\n", GetLastError());
128 return FALSE;
129 }
130
131 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
132 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
133 0,
134 KEY_SET_VALUE,
135 &hKey);
136 if (Error != ERROR_SUCCESS)
137 {
138 DPRINT1("Error: %lu\n", Error);
139 SetLastError((DWORD)Error);
140 return FALSE;
141 }
142
143 /* Store profiles directory path */
144 dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR);
145 Error = RegSetValueExW(hKey,
146 L"ProfilesDirectory",
147 0,
148 REG_EXPAND_SZ,
149 (LPBYTE)szBuffer,
150 dwLength);
151 if (Error != ERROR_SUCCESS)
152 {
153 DPRINT1("Error: %lu\n", Error);
154 RegCloseKey(hKey);
155 SetLastError((DWORD)Error);
156 return FALSE;
157 }
158
159 /* Expand it */
160 if (!ExpandEnvironmentStringsW(szBuffer,
161 szProfilesPath,
162 MAX_PATH))
163 {
164 DPRINT1("Error: %lu\n", GetLastError());
165 RegCloseKey(hKey);
166 return FALSE;
167 }
168
169 /* Create profiles directory */
170 if (!CreateDirectoryW(szProfilesPath, NULL))
171 {
172 if (GetLastError() != ERROR_ALREADY_EXISTS)
173 {
174 DPRINT1("Error: %lu\n", GetLastError());
175 RegCloseKey(hKey);
176 return FALSE;
177 }
178 }
179
180 /* Set 'DefaultUserProfile' value */
181 wcscpy(szBuffer, L"Default User");
182 if (!AppendSystemPostfix(szBuffer, MAX_PATH))
183 {
184 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
185 RegCloseKey(hKey);
186 return FALSE;
187 }
188
189 dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR);
190 Error = RegSetValueExW(hKey,
191 L"DefaultUserProfile",
192 0,
193 REG_SZ,
194 (LPBYTE)szBuffer,
195 dwLength);
196 if (Error != ERROR_SUCCESS)
197 {
198 DPRINT1("Error: %lu\n", Error);
199 RegCloseKey(hKey);
200 SetLastError((DWORD)Error);
201 return FALSE;
202 }
203
204 RegCloseKey(hKey);
205
206 /* Create 'Default User' profile directory */
207 wcscpy(szProfilePath, szProfilesPath);
208 wcscat(szProfilePath, L"\\");
209 wcscat(szProfilePath, szBuffer);
210 if (!CreateDirectoryW (szProfilePath, NULL))
211 {
212 if (GetLastError() != ERROR_ALREADY_EXISTS)
213 {
214 DPRINT1("Error: %lu\n", GetLastError());
215 return FALSE;
216 }
217 }
218
219 /* Set current user profile */
220 SetEnvironmentVariableW(L"USERPROFILE", szProfilePath);
221
222 /* Create 'Default User' subdirectories */
223 /* FIXME: Get these paths from the registry */
224 lpFolderData = &UserShellFolders[0];
225 while (lpFolderData->lpValueName != NULL)
226 {
227 wcscpy(szBuffer, szProfilePath);
228 wcscat(szBuffer, L"\\");
229
230 /* Append the folder name */
231 dwLength = wcslen(szBuffer);
232 if (!LoadStringW(hInstance,
233 lpFolderData->uId,
234 &szBuffer[dwLength],
235 MAX_PATH - dwLength))
236 {
237 /* Use the default name instead */
238 wcscat(szBuffer, lpFolderData->lpPath);
239 }
240
241 if (!CreateDirectoryW(szBuffer, NULL))
242 {
243 if (GetLastError() != ERROR_ALREADY_EXISTS)
244 {
245 DPRINT1("Error: %lu\n", GetLastError());
246 return FALSE;
247 }
248 }
249
250 if (lpFolderData->bHidden == TRUE)
251 {
252 SetFileAttributesW(szBuffer,
253 FILE_ATTRIBUTE_HIDDEN);
254 }
255
256 lpFolderData++;
257 }
258
259 /* Set default 'Shell Folders' values */
260 Error = RegOpenKeyExW(HKEY_USERS,
261 L".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
262 0,
263 KEY_SET_VALUE,
264 &hKey);
265 if (Error != ERROR_SUCCESS)
266 {
267 DPRINT1("Error: %lu\n", Error);
268 SetLastError((DWORD)Error);
269 return FALSE;
270 }
271
272 lpFolderData = &UserShellFolders[0];
273 while (lpFolderData->lpValueName != NULL)
274 {
275 if (lpFolderData->bShellFolder)
276 {
277 wcscpy(szBuffer, szProfilePath);
278 wcscat(szBuffer, L"\\");
279
280 /* Append the folder name */
281 dwLength = wcslen(szBuffer);
282 if (!LoadStringW(hInstance,
283 lpFolderData->uId,
284 &szBuffer[dwLength],
285 MAX_PATH - dwLength))
286 {
287 /* Use the default name instead */
288 wcscat(szBuffer, lpFolderData->lpPath);
289 }
290
291 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
292 Error = RegSetValueExW(hKey,
293 lpFolderData->lpValueName,
294 0,
295 REG_SZ,
296 (LPBYTE)szBuffer,
297 dwLength);
298 if (Error != ERROR_SUCCESS)
299 {
300 DPRINT1("Error: %lu\n", Error);
301 RegCloseKey(hKey);
302 SetLastError((DWORD)Error);
303 return FALSE;
304 }
305 }
306
307 lpFolderData++;
308 }
309
310 /* Set 'Fonts' folder path */
311 GetWindowsDirectoryW(szBuffer, MAX_PATH);
312 wcscat(szBuffer, L"\\fonts");
313
314 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
315 Error = RegSetValueExW(hKey,
316 L"Fonts",
317 0,
318 REG_SZ,
319 (LPBYTE)szBuffer,
320 dwLength);
321 if (Error != ERROR_SUCCESS)
322 {
323 DPRINT1("Error: %lu\n", Error);
324 RegCloseKey(hKey);
325 SetLastError((DWORD)Error);
326 return FALSE;
327 }
328
329 RegCloseKey(hKey);
330
331 /* Set default 'User Shell Folders' values */
332 Error = RegOpenKeyExW(HKEY_USERS,
333 L".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
334 0,
335 KEY_SET_VALUE,
336 &hKey);
337 if (Error != ERROR_SUCCESS)
338 {
339 DPRINT1("Error: %lu\n", Error);
340 SetLastError((DWORD)Error);
341 return FALSE;
342 }
343
344 lpFolderData = &UserShellFolders[0];
345 while (lpFolderData->lpValueName != NULL)
346 {
347 if (lpFolderData->bUserShellFolder)
348 {
349 wcscpy(szBuffer, L"%USERPROFILE%\\");
350
351 /* Append the folder name */
352 dwLength = wcslen(szBuffer);
353 if (!LoadStringW(hInstance,
354 lpFolderData->uId,
355 &szBuffer[dwLength],
356 MAX_PATH - dwLength))
357 {
358 /* Use the default name instead */
359 wcscat(szBuffer, lpFolderData->lpPath);
360 }
361
362 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
363 Error = RegSetValueExW(hKey,
364 lpFolderData->lpValueName,
365 0,
366 REG_EXPAND_SZ,
367 (LPBYTE)szBuffer,
368 dwLength);
369 if (Error != ERROR_SUCCESS)
370 {
371 DPRINT1("Error: %lu\n", Error);
372 RegCloseKey(hKey);
373 SetLastError((DWORD)Error);
374 return FALSE;
375 }
376 }
377
378 lpFolderData++;
379 }
380
381 RegCloseKey(hKey);
382
383 /* Set 'AllUsersProfile' value */
384 wcscpy(szBuffer, L"All Users");
385 if (!AppendSystemPostfix(szBuffer, MAX_PATH))
386 {
387 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
388 return FALSE;
389 }
390
391 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
392 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
393 0,
394 KEY_SET_VALUE,
395 &hKey);
396 if (Error != ERROR_SUCCESS)
397 {
398 DPRINT1("Error: %lu\n", Error);
399 SetLastError((DWORD)Error);
400 return FALSE;
401 }
402
403 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
404 Error = RegSetValueExW(hKey,
405 L"AllUsersProfile",
406 0,
407 REG_SZ,
408 (LPBYTE)szBuffer,
409 dwLength);
410 if (Error != ERROR_SUCCESS)
411 {
412 DPRINT1("Error: %lu\n", Error);
413 RegCloseKey(hKey);
414 SetLastError((DWORD)Error);
415 return FALSE;
416 }
417
418 RegCloseKey(hKey);
419
420 /* Create 'All Users' profile directory */
421 wcscpy(szProfilePath, szProfilesPath);
422 wcscat(szProfilePath, L"\\");
423 wcscat(szProfilePath, szBuffer);
424 if (!CreateDirectoryW(szProfilePath, NULL))
425 {
426 if (GetLastError() != ERROR_ALREADY_EXISTS)
427 {
428 DPRINT1("Error: %lu\n", GetLastError());
429 return FALSE;
430 }
431 }
432
433 /* Set 'All Users' profile */
434 SetEnvironmentVariableW(L"ALLUSERSPROFILE", szProfilePath);
435
436 /* Create 'All Users' subdirectories */
437 /* FIXME: Take these paths from the registry */
438 lpFolderData = &CommonShellFolders[0];
439 while (lpFolderData->lpValueName != NULL)
440 {
441 wcscpy(szBuffer, szProfilePath);
442 wcscat(szBuffer, L"\\");
443
444 /* Append the folder name */
445 dwLength = wcslen(szBuffer);
446 if (!LoadStringW(hInstance,
447 lpFolderData->uId,
448 &szBuffer[dwLength],
449 MAX_PATH - dwLength))
450 {
451 /* Use the default name instead */
452 wcscat(szBuffer, lpFolderData->lpPath);
453 }
454
455 if (!CreateDirectoryW(szBuffer, NULL))
456 {
457 if (GetLastError() != ERROR_ALREADY_EXISTS)
458 {
459 DPRINT1("Error: %lu\n", GetLastError());
460 return FALSE;
461 }
462 }
463
464 if (lpFolderData->bHidden)
465 {
466 SetFileAttributesW(szBuffer,
467 FILE_ATTRIBUTE_HIDDEN);
468 }
469
470 lpFolderData++;
471 }
472
473 /* Set common 'Shell Folders' values */
474 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
475 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
476 0,
477 KEY_SET_VALUE,
478 &hKey);
479 if (Error != ERROR_SUCCESS)
480 {
481 DPRINT1("Error: %lu\n", Error);
482 SetLastError((DWORD)Error);
483 return FALSE;
484 }
485
486 lpFolderData = &CommonShellFolders[0];
487 while (lpFolderData->lpValueName != NULL)
488 {
489 if (lpFolderData->bShellFolder)
490 {
491 wcscpy(szBuffer, szProfilePath);
492 wcscat(szBuffer, L"\\");
493
494 /* Append the folder name */
495 dwLength = wcslen(szBuffer);
496 if (!LoadStringW(hInstance,
497 lpFolderData->uId,
498 &szBuffer[dwLength],
499 MAX_PATH - dwLength))
500 {
501 /* Use the default name instead */
502 wcscat(szBuffer, lpFolderData->lpPath);
503 }
504
505 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
506 Error = RegSetValueExW(hKey,
507 lpFolderData->lpValueName,
508 0,
509 REG_SZ,
510 (LPBYTE)szBuffer,
511 dwLength);
512 if (Error != ERROR_SUCCESS)
513 {
514 DPRINT1("Error: %lu\n", Error);
515 RegCloseKey(hKey);
516 SetLastError((DWORD)Error);
517 return FALSE;
518 }
519 }
520
521 lpFolderData++;
522 }
523
524 RegCloseKey(hKey);
525
526 /* Set common 'User Shell Folders' values */
527 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
528 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
529 0,
530 KEY_SET_VALUE,
531 &hKey);
532 if (Error != ERROR_SUCCESS)
533 {
534 DPRINT1("Error: %lu\n", Error);
535 SetLastError((DWORD)Error);
536 return FALSE;
537 }
538
539 lpFolderData = &CommonShellFolders[0];
540 while (lpFolderData->lpValueName != NULL)
541 {
542 if (lpFolderData->bUserShellFolder)
543 {
544 wcscpy(szBuffer, L"%ALLUSERSPROFILE%\\");
545
546 /* Append the folder name */
547 dwLength = wcslen(szBuffer);
548 if (!LoadStringW(hInstance,
549 lpFolderData->uId,
550 &szBuffer[dwLength],
551 MAX_PATH - dwLength))
552 {
553 /* Use the default name instead */
554 wcscat(szBuffer, lpFolderData->lpPath);
555 }
556
557 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
558 Error = RegSetValueExW(hKey,
559 lpFolderData->lpValueName,
560 0,
561 REG_EXPAND_SZ,
562 (LPBYTE)szBuffer,
563 dwLength);
564 if (Error != ERROR_SUCCESS)
565 {
566 DPRINT1("Error: %lu\n", Error);
567 RegCloseKey(hKey);
568 SetLastError((DWORD)Error);
569 return FALSE;
570 }
571 }
572
573 lpFolderData++;
574 }
575
576 RegCloseKey(hKey);
577
578 /* Load 'Program Files' location */
579 if (!LoadStringW(hInstance,
580 IDS_PROGRAMFILES,
581 szBuffer,
582 MAX_PATH))
583 {
584 DPRINT1("Error: %lu\n", GetLastError());
585 return FALSE;
586 }
587
588 if (!LoadStringW(hInstance,
589 IDS_COMMONFILES,
590 szCommonFilesDirPath,
591 MAX_PATH))
592 {
593 DPRINT1("Warning: %lu\n", GetLastError());
594 }
595
596 /* Expand it */
597 if (!ExpandEnvironmentStringsW(szBuffer,
598 szProfilesPath,
599 MAX_PATH))
600 {
601 DPRINT1("Error: %lu\n", GetLastError());
602 return FALSE;
603 }
604
605 wcscpy(szBuffer, szProfilesPath);
606 wcscat(szBuffer, L"\\");
607 wcscat(szBuffer, szCommonFilesDirPath);
608
609 if (!ExpandEnvironmentStringsW(szBuffer,
610 szCommonFilesDirPath,
611 MAX_PATH))
612 {
613 DPRINT1("Warning: %lu\n", GetLastError());
614 }
615
616 /* Store it */
617 Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
618 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
619 0,
620 KEY_SET_VALUE,
621 &hKey);
622 if (Error != ERROR_SUCCESS)
623 {
624 DPRINT1("Error: %lu\n", Error);
625 SetLastError((DWORD)Error);
626 return FALSE;
627 }
628
629 dwLength = (wcslen (szProfilesPath) + 1) * sizeof(WCHAR);
630 Error = RegSetValueExW(hKey,
631 L"ProgramFilesDir",
632 0,
633 REG_SZ,
634 (LPBYTE)szProfilesPath,
635 dwLength);
636 if (Error != ERROR_SUCCESS)
637 {
638 DPRINT1("Error: %lu\n", Error);
639 RegCloseKey(hKey);
640 SetLastError((DWORD)Error);
641 return FALSE;
642 }
643
644 dwLength = (wcslen(szCommonFilesDirPath) + 1) * sizeof(WCHAR);
645 Error = RegSetValueExW(hKey,
646 L"CommonFilesDir",
647 0,
648 REG_SZ,
649 (LPBYTE)szCommonFilesDirPath,
650 dwLength);
651 if (Error != ERROR_SUCCESS)
652 {
653 DPRINT1("Warning: %lu\n", Error);
654 }
655
656 RegCloseKey (hKey);
657
658 /* Create directory */
659 if (!CreateDirectoryW(szProfilesPath, NULL))
660 {
661 if (GetLastError () != ERROR_ALREADY_EXISTS)
662 {
663 DPRINT1("Error: %lu\n", GetLastError());
664 return FALSE;
665 }
666 }
667
668 /* Create directory */
669 if (!CreateDirectoryW(szCommonFilesDirPath, NULL))
670 {
671 if (GetLastError () != ERROR_ALREADY_EXISTS)
672 {
673 DPRINT1("Warning: %lu\n", GetLastError());
674 }
675 }
676
677 DPRINT("Success\n");
678
679 return TRUE;
680 }
681
682
683 BOOL
684 UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath,
685 HKEY hUserKey)
686 {
687 WCHAR szBuffer[MAX_PATH];
688 DWORD dwLength;
689 PFOLDERDATA lpFolderData;
690 HKEY hFoldersKey;
691 LONG Error;
692
693 DPRINT("UpdateUsersShellFolderSettings() called\n");
694
695 DPRINT("User profile path: %S\n", lpUserProfilePath);
696
697 Error = RegOpenKeyExW(hUserKey,
698 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
699 0,
700 KEY_SET_VALUE,
701 &hFoldersKey);
702 if (Error != ERROR_SUCCESS)
703 {
704 DPRINT1("Error: %lu\n", Error);
705 SetLastError((DWORD)Error);
706 return FALSE;
707 }
708
709 lpFolderData = &UserShellFolders[0];
710 while (lpFolderData->lpValueName != NULL)
711 {
712 if (lpFolderData->bShellFolder)
713 {
714 wcscpy(szBuffer, lpUserProfilePath);
715 wcscat(szBuffer, L"\\");
716
717 /* Append the folder name */
718 dwLength = wcslen(szBuffer);
719 if (!LoadStringW(hInstance,
720 lpFolderData->uId,
721 &szBuffer[dwLength],
722 MAX_PATH - dwLength))
723 {
724 /* Use the default name instead */
725 wcscat(szBuffer, lpFolderData->lpPath);
726 }
727
728 DPRINT("%S: %S\n", lpFolderData->lpValueName, szBuffer);
729
730 dwLength = (wcslen(szBuffer) + 1) * sizeof(WCHAR);
731 Error = RegSetValueExW(hFoldersKey,
732 lpFolderData->lpValueName,
733 0,
734 REG_SZ,
735 (LPBYTE)szBuffer,
736 dwLength);
737 if (Error != ERROR_SUCCESS)
738 {
739 DPRINT1("Error: %lu\n", Error);
740 RegCloseKey(hFoldersKey);
741 SetLastError((DWORD)Error);
742 return FALSE;
743 }
744 }
745
746 lpFolderData++;
747 }
748
749 RegCloseKey(hFoldersKey);
750
751 DPRINT("UpdateUsersShellFolderSettings() done\n");
752
753 return TRUE;
754 }
755
756 /* EOF */