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/setup.c
24 * PURPOSE: Profile setup functions
25 * PROGRAMMER: Eric Kohl
34 typedef struct _FOLDERDATA
41 BOOL bUserShellFolder
;
42 } FOLDERDATA
, *PFOLDERDATA
;
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
}
74 CommonShellFolders
[] =
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
}
93 DebugPrint(char* fmt
,...)
99 vsprintf(buffer
, fmt
, ap
);
102 OutputDebugStringA(buffer
);
107 InitializeProfiles (VOID
)
109 WCHAR szProfilesPath
[MAX_PATH
];
110 WCHAR szProfilePath
[MAX_PATH
];
111 WCHAR szBuffer
[MAX_PATH
];
113 PFOLDERDATA lpFolderData
;
116 /* Load profiles directory path */
117 if (!LoadStringW(hInstance
,
122 DPRINT1("Error: %lu\n", GetLastError());
126 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE
,
127 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
132 DPRINT1("Error: %lu\n", GetLastError());
136 /* Store profiles directory path */
137 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
138 if (RegSetValueExW (hKey
,
139 L
"ProfilesDirectory",
145 DPRINT1("Error: %lu\n", GetLastError());
151 if (!ExpandEnvironmentStringsW (szBuffer
,
155 DPRINT1("Error: %lu\n", GetLastError());
160 /* Create profiles directory */
161 if (!CreateDirectoryW (szProfilesPath
, NULL
))
163 if (GetLastError () != ERROR_ALREADY_EXISTS
)
165 DPRINT1("Error: %lu\n", GetLastError());
171 /* Set 'DefaultUserProfile' value */
172 wcscpy (szBuffer
, L
"Default User");
173 if (!AppendSystemPostfix (szBuffer
, MAX_PATH
))
175 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
180 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
181 if (RegSetValueExW (hKey
,
182 L
"DefaultUserProfile",
188 DPRINT1("Error: %lu\n", GetLastError());
195 /* Create 'Default User' profile directory */
196 wcscpy (szProfilePath
, szProfilesPath
);
197 wcscat (szProfilePath
, L
"\\");
198 wcscat (szProfilePath
, szBuffer
);
199 if (!CreateDirectoryW (szProfilePath
, NULL
))
201 if (GetLastError () != ERROR_ALREADY_EXISTS
)
203 DPRINT1("Error: %lu\n", GetLastError());
208 /* Set current user profile */
209 SetEnvironmentVariableW(L
"USERPROFILE", szProfilePath
);
211 /* Create 'Default User' subdirectories */
212 /* FIXME: Get these paths from the registry */
213 lpFolderData
= &UserShellFolders
[0];
214 while (lpFolderData
->lpValueName
!= NULL
)
216 wcscpy(szBuffer
, szProfilePath
);
217 wcscat(szBuffer
, L
"\\");
219 /* Append the folder name */
220 dwLength
= wcslen(szBuffer
);
221 if (!LoadStringW(hInstance
,
224 MAX_PATH
- dwLength
))
226 /* Use the default name instead */
227 wcscat(szBuffer
, lpFolderData
->lpPath
);
230 if (!CreateDirectoryW(szBuffer
, NULL
))
232 if (GetLastError() != ERROR_ALREADY_EXISTS
)
234 DPRINT1("Error: %lu\n", GetLastError());
239 if (lpFolderData
->bHidden
== TRUE
)
241 SetFileAttributesW(szBuffer
,
242 FILE_ATTRIBUTE_HIDDEN
);
248 /* Set default 'Shell Folders' values */
249 if (RegOpenKeyExW(HKEY_USERS
,
250 L
".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
255 DPRINT1("Error: %lu\n", GetLastError());
259 lpFolderData
= &UserShellFolders
[0];
260 while (lpFolderData
->lpValueName
!= NULL
)
262 if (lpFolderData
->bShellFolder
)
264 wcscpy(szBuffer
, szProfilePath
);
265 wcscat(szBuffer
, L
"\\");
267 /* Append the folder name */
268 dwLength
= wcslen(szBuffer
);
269 if (!LoadStringW(hInstance
,
272 MAX_PATH
- dwLength
))
274 /* Use the default name instead */
275 wcscat(szBuffer
, lpFolderData
->lpPath
);
278 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
279 if (RegSetValueExW(hKey
,
280 lpFolderData
->lpValueName
,
286 DPRINT1("Error: %lu\n", GetLastError());
295 /* Set 'Fonts' folder path */
296 GetWindowsDirectoryW(szBuffer
, MAX_PATH
);
297 wcscat(szBuffer
, L
"\\media\\fonts");
299 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
300 if (RegSetValueExW(hKey
,
307 DPRINT1("Error: %lu\n", GetLastError());
314 /* Set default 'User Shell Folders' values */
315 if (RegOpenKeyExW(HKEY_USERS
,
316 L
".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
321 DPRINT1("Error: %lu\n", GetLastError());
325 lpFolderData
= &UserShellFolders
[0];
326 while (lpFolderData
->lpValueName
!= NULL
)
328 if (lpFolderData
->bUserShellFolder
)
330 wcscpy(szBuffer
, L
"%USERPROFILE%\\");
332 /* Append the folder name */
333 dwLength
= wcslen(szBuffer
);
334 if (!LoadStringW(hInstance
,
337 MAX_PATH
- dwLength
))
339 /* Use the default name instead */
340 wcscat(szBuffer
, lpFolderData
->lpPath
);
343 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
344 if (RegSetValueExW(hKey
,
345 lpFolderData
->lpValueName
,
351 DPRINT1("Error: %lu\n", GetLastError());
363 /* Set 'AllUsersProfile' value */
364 wcscpy(szBuffer
, L
"All Users");
365 if (!AppendSystemPostfix(szBuffer
, MAX_PATH
))
367 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
371 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
372 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
377 DPRINT1("Error: %lu\n", GetLastError());
381 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
382 if (RegSetValueExW(hKey
,
389 DPRINT1("Error: %lu\n", GetLastError());
397 /* Create 'All Users' profile directory */
398 wcscpy(szProfilePath
, szProfilesPath
);
399 wcscat(szProfilePath
, L
"\\");
400 wcscat(szProfilePath
, szBuffer
);
401 if (!CreateDirectoryW(szProfilePath
, NULL
))
403 if (GetLastError() != ERROR_ALREADY_EXISTS
)
405 DPRINT1("Error: %lu\n", GetLastError());
410 /* Set 'All Users' profile */
411 SetEnvironmentVariableW(L
"ALLUSERSPROFILE", szProfilePath
);
413 /* Create 'All Users' subdirectories */
414 /* FIXME: Take these paths from the registry */
415 lpFolderData
= &CommonShellFolders
[0];
416 while (lpFolderData
->lpValueName
!= NULL
)
418 wcscpy(szBuffer
, szProfilePath
);
419 wcscat(szBuffer
, L
"\\");
421 /* Append the folder name */
422 dwLength
= wcslen(szBuffer
);
423 if (!LoadStringW(hInstance
,
426 MAX_PATH
- dwLength
))
428 /* Use the default name instead */
429 wcscat(szBuffer
, lpFolderData
->lpPath
);
432 if (!CreateDirectoryW(szBuffer
, NULL
))
434 if (GetLastError() != ERROR_ALREADY_EXISTS
)
436 DPRINT1("Error: %lu\n", GetLastError());
441 if (lpFolderData
->bHidden
)
443 SetFileAttributesW(szBuffer
,
444 FILE_ATTRIBUTE_HIDDEN
);
450 /* Set common 'Shell Folders' values */
451 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
452 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
457 DPRINT1("Error: %lu\n", GetLastError());
461 lpFolderData
= &CommonShellFolders
[0];
462 while (lpFolderData
->lpValueName
!= NULL
)
464 if (lpFolderData
->bShellFolder
)
466 wcscpy(szBuffer
, szProfilePath
);
467 wcscat(szBuffer
, L
"\\");
469 /* Append the folder name */
470 dwLength
= wcslen(szBuffer
);
471 if (!LoadStringW(hInstance
,
474 MAX_PATH
- dwLength
))
476 /* Use the default name instead */
477 wcscat(szBuffer
, lpFolderData
->lpPath
);
480 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
481 if (RegSetValueExW(hKey
,
482 lpFolderData
->lpValueName
,
488 DPRINT1("Error: %lu\n", GetLastError());
499 /* Set common 'User Shell Folders' values */
500 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
501 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
506 DPRINT1("Error: %lu\n", GetLastError());
510 lpFolderData
= &CommonShellFolders
[0];
511 while (lpFolderData
->lpValueName
!= NULL
)
513 if (lpFolderData
->bUserShellFolder
)
515 wcscpy(szBuffer
, L
"%ALLUSERSPROFILE%\\");
517 /* Append the folder name */
518 dwLength
= wcslen(szBuffer
);
519 if (!LoadStringW(hInstance
,
522 MAX_PATH
- dwLength
))
524 /* Use the default name instead */
525 wcscat(szBuffer
, lpFolderData
->lpPath
);
528 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
529 if (RegSetValueExW(hKey
,
530 lpFolderData
->lpValueName
,
536 DPRINT1("Error: %lu\n", GetLastError());
547 /* Load 'Program Files' location */
548 if (!LoadStringW(hInstance
,
553 DPRINT1("Error: %lu\n", GetLastError());
558 if (!ExpandEnvironmentStringsW (szBuffer
,
562 DPRINT1("Error: %lu\n", GetLastError());
568 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE
,
569 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
574 DPRINT1("Error: %lu\n", GetLastError());
578 dwLength
= (wcslen (szProfilesPath
) + 1) * sizeof(WCHAR
);
579 if (RegSetValueExW (hKey
,
583 (LPBYTE
)szProfilesPath
,
586 DPRINT1("Error: %lu\n", GetLastError());
593 /* Create directory */
594 if (!CreateDirectoryW (szProfilesPath
, NULL
))
596 if (GetLastError () != ERROR_ALREADY_EXISTS
)
598 DPRINT1("Error: %lu\n", GetLastError());
611 UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath
,
614 WCHAR szBuffer
[MAX_PATH
];
616 PFOLDERDATA lpFolderData
;
619 DPRINT("UpdateUsersShellFolderSettings() called\n");
621 DPRINT("User profile path: %S\n", lpUserProfilePath
);
623 if (RegOpenKeyExW(hUserKey
,
624 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
629 DPRINT1("Error: %lu\n", GetLastError());
633 lpFolderData
= &UserShellFolders
[0];
634 while (lpFolderData
->lpValueName
!= NULL
)
636 if (lpFolderData
->bShellFolder
)
638 wcscpy(szBuffer
, lpUserProfilePath
);
639 wcscat(szBuffer
, L
"\\");
641 /* Append the folder name */
642 dwLength
= wcslen(szBuffer
);
643 if (!LoadStringW(hInstance
,
646 MAX_PATH
- dwLength
))
648 /* Use the default name instead */
649 wcscat(szBuffer
, lpFolderData
->lpPath
);
652 DPRINT("%S: %S\n", lpFolderData
->lpValueName
, szBuffer
);
654 dwLength
= (wcslen(szBuffer
) + 1) * sizeof(WCHAR
);
655 if (RegSetValueExW(hFoldersKey
,
656 lpFolderData
->lpValueName
,
662 DPRINT1("Error: %lu\n", GetLastError());
663 RegCloseKey(hFoldersKey
);
671 RegCloseKey(hFoldersKey
);
673 DPRINT("UpdateUsersShellFolderSettings() done\n");