45bb29afa9cdec222441cae680a26f3a342a705c
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.
19 /* $Id: setup.c,v 1.8 2004/10/02 12:31:28 ekohl Exp $
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
30 typedef struct _FOLDERDATA
36 BOOL bUserShellFolder
;
37 } FOLDERDATA
, *PFOLDERDATA
;
43 {L
"AppData", L
"Application Data", TRUE
, TRUE
, TRUE
},
44 {L
"Desktop", L
"Desktop", FALSE
, TRUE
, TRUE
},
45 {L
"Favorites", L
"Favorites", FALSE
, TRUE
, TRUE
},
46 {L
"Personal", L
"My Documents", FALSE
, TRUE
, TRUE
},
47 {L
"PrintHood", L
"PrintHood", TRUE
, TRUE
, TRUE
},
48 {L
"Recent", L
"Recent", TRUE
, TRUE
, TRUE
},
49 {L
"SendTo", L
"SendTo", FALSE
, TRUE
, TRUE
},
50 {L
"Templates", L
"Templates", FALSE
, TRUE
, TRUE
},
51 {L
"Start Menu", L
"Start Menu", FALSE
, TRUE
, TRUE
},
52 {L
"Programs", L
"Start Menu\\Programs", FALSE
, TRUE
, TRUE
},
53 {L
"Startup", L
"Start Menu\\Programs\\Startup", FALSE
, TRUE
, TRUE
},
54 {L
"Local Settings", L
"Local Settings", TRUE
, TRUE
, TRUE
},
55 {L
"Local AppData", L
"Local Settings\\Application Data", TRUE
, TRUE
, TRUE
},
56 {L
"Temp", L
"Local Settings\\Temp", FALSE
, FALSE
, FALSE
},
57 {NULL
, NULL
, FALSE
, FALSE
, FALSE
}
62 CommonShellFolders
[] =
64 {L
"Common AppData", L
"Application Data", TRUE
, TRUE
, TRUE
},
65 {L
"Common Desktop", L
"Desktop", FALSE
, TRUE
, TRUE
},
66 {L
"Common Favorites", L
"Favorites", FALSE
, TRUE
, TRUE
},
67 {L
"Common Start Menu", L
"Start Menu", FALSE
, TRUE
, TRUE
},
68 {L
"Common Programs", L
"Start Menu\\Programs", FALSE
, TRUE
, TRUE
},
69 {L
"Common Administrative Tools", L
"Start Menu\\Programs\\Administrative Tools", FALSE
, TRUE
, FALSE
},
70 {L
"Common Startup", L
"Start Menu\\Programs\\Startup", FALSE
, TRUE
, TRUE
},
71 {L
"Common Templates", L
"Templates", TRUE
, TRUE
, TRUE
},
72 {L
"Common Documents", L
"My Documents", FALSE
, TRUE
, TRUE
},
73 {L
"CommonPictures", L
"My Documents\\My Pictures", FALSE
, TRUE
, TRUE
},
74 {L
"CommonMusic", L
"My Documents\\My Music", FALSE
, TRUE
, TRUE
},
75 {L
"CommonVideo", L
"My Documents\\My Videos", FALSE
, TRUE
, TRUE
},
76 {NULL
, NULL
, FALSE
, FALSE
, FALSE
}
81 DebugPrint(char* fmt
,...)
87 vsprintf(buffer
, fmt
, ap
);
90 OutputDebugStringA(buffer
);
95 InitializeProfiles (VOID
)
97 WCHAR szProfilesPath
[MAX_PATH
];
98 WCHAR szProfilePath
[MAX_PATH
];
99 WCHAR szBuffer
[MAX_PATH
];
101 PFOLDERDATA lpFolderData
;
104 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE
,
105 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
110 DPRINT1("Error: %lu\n", GetLastError());
114 /* Get profiles path */
115 dwLength
= MAX_PATH
* sizeof(WCHAR
);
116 if (RegQueryValueExW (hKey
,
117 L
"ProfilesDirectory",
123 DPRINT1("Error: %lu\n", GetLastError());
129 if (!ExpandEnvironmentStringsW (szBuffer
,
133 DPRINT1("Error: %lu\n", GetLastError());
138 /* Create profiles directory */
139 if (!CreateDirectoryW (szProfilesPath
, NULL
))
141 if (GetLastError () != ERROR_ALREADY_EXISTS
)
143 DPRINT1("Error: %lu\n", GetLastError());
149 /* Set 'DefaultUserProfile' value */
150 wcscpy (szBuffer
, L
"Default User");
151 if (!AppendSystemPostfix (szBuffer
, MAX_PATH
))
153 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
158 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
159 if (RegSetValueExW (hKey
,
160 L
"DefaultUserProfile",
166 DPRINT1("Error: %lu\n", GetLastError());
173 /* Create 'Default User' profile directory */
174 wcscpy (szProfilePath
, szProfilesPath
);
175 wcscat (szProfilePath
, L
"\\");
176 wcscat (szProfilePath
, szBuffer
);
177 if (!CreateDirectoryW (szProfilePath
, NULL
))
179 if (GetLastError () != ERROR_ALREADY_EXISTS
)
181 DPRINT1("Error: %lu\n", GetLastError());
186 /* Set current user profile */
187 SetEnvironmentVariableW (L
"USERPROFILE", szProfilePath
);
189 /* Create 'Default User' subdirectories */
190 /* FIXME: Get these paths from the registry */
191 lpFolderData
= &UserShellFolders
[0];
192 while (lpFolderData
->ValueName
!= NULL
)
194 wcscpy(szBuffer
, szProfilePath
);
195 wcscat(szBuffer
, L
"\\");
196 wcscat(szBuffer
, lpFolderData
->Path
);
198 if (!CreateDirectoryW(szBuffer
, NULL
))
200 if (GetLastError () != ERROR_ALREADY_EXISTS
)
202 DPRINT1("Error: %lu\n", GetLastError());
207 if (lpFolderData
->Hidden
== TRUE
)
209 SetFileAttributesW (szBuffer
,
210 FILE_ATTRIBUTE_HIDDEN
);
216 /* Set default 'Shell Folders' values */
217 if (RegOpenKeyExW(HKEY_USERS
,
218 L
".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
223 DPRINT1("Error: %lu\n", GetLastError());
227 lpFolderData
= &UserShellFolders
[0];
228 while (lpFolderData
->ValueName
!= NULL
)
230 if (lpFolderData
->bShellFolder
)
232 wcscpy(szBuffer
, szProfilePath
);
233 wcscat(szBuffer
, L
"\\");
234 wcscat(szBuffer
, lpFolderData
->Path
);
236 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
237 if (RegSetValueExW(hKey
,
238 lpFolderData
->ValueName
,
244 DPRINT1("Error: %lu\n", GetLastError());
253 /* Set 'Fonts' folder path */
254 GetWindowsDirectory(szBuffer
, MAX_PATH
);
255 wcscat(szBuffer
, L
"\\media\\fonts");
257 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
258 if (RegSetValueExW(hKey
,
265 DPRINT1("Error: %lu\n", GetLastError());
272 /* Set default 'User Shell Folders' values */
273 if (RegOpenKeyExW(HKEY_USERS
,
274 L
".Default\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
279 DPRINT1("Error: %lu\n", GetLastError());
283 lpFolderData
= &UserShellFolders
[0];
284 while (lpFolderData
->ValueName
!= NULL
)
286 if (lpFolderData
->bUserShellFolder
)
288 wcscpy(szBuffer
, L
"%USERPROFILE%\\");
289 wcscat(szBuffer
, lpFolderData
->Path
);
291 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
292 if (RegSetValueExW(hKey
,
293 lpFolderData
->ValueName
,
299 DPRINT1("Error: %lu\n", GetLastError());
311 /* Set 'AllUsersProfile' value */
312 wcscpy (szBuffer
, L
"All Users");
313 if (!AppendSystemPostfix (szBuffer
, MAX_PATH
))
315 DPRINT1("AppendSystemPostfix() failed\n", GetLastError());
319 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE
,
320 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
325 DPRINT1("Error: %lu\n", GetLastError());
329 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
330 if (RegSetValueExW (hKey
,
337 DPRINT1("Error: %lu\n", GetLastError());
345 /* Create 'All Users' profile directory */
346 wcscpy (szProfilePath
, szProfilesPath
);
347 wcscat (szProfilePath
, L
"\\");
348 wcscat (szProfilePath
, szBuffer
);
349 if (!CreateDirectoryW (szProfilePath
, NULL
))
351 if (GetLastError () != ERROR_ALREADY_EXISTS
)
353 DPRINT1("Error: %lu\n", GetLastError());
358 /* Set 'All Users' profile */
359 SetEnvironmentVariableW (L
"ALLUSERSPROFILE", szProfilePath
);
361 /* Create 'All Users' subdirectories */
362 /* FIXME: Take these paths from the registry */
363 lpFolderData
= &CommonShellFolders
[0];
364 while (lpFolderData
->ValueName
!= NULL
)
366 wcscpy(szBuffer
, szProfilePath
);
367 wcscat(szBuffer
, L
"\\");
368 wcscat(szBuffer
, lpFolderData
->Path
);
370 if (!CreateDirectoryW(szBuffer
, NULL
))
372 if (GetLastError () != ERROR_ALREADY_EXISTS
)
374 DPRINT1("Error: %lu\n", GetLastError());
379 if (lpFolderData
->Hidden
)
381 SetFileAttributesW(szBuffer
,
382 FILE_ATTRIBUTE_HIDDEN
);
388 /* Set common 'Shell Folders' values */
389 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
390 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
395 DPRINT1("Error: %lu\n", GetLastError());
399 lpFolderData
= &CommonShellFolders
[0];
400 while (lpFolderData
->ValueName
!= NULL
)
402 if (lpFolderData
->bShellFolder
)
404 wcscpy(szBuffer
, szProfilePath
);
405 wcscat(szBuffer
, L
"\\");
406 wcscat(szBuffer
, lpFolderData
->Path
);
408 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
409 if (RegSetValueExW(hKey
,
410 lpFolderData
->ValueName
,
416 DPRINT1("Error: %lu\n", GetLastError());
427 /* Set common 'User Shell Folders' values */
428 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
429 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
434 DPRINT1("Error: %lu\n", GetLastError());
438 lpFolderData
= &CommonShellFolders
[0];
439 while (lpFolderData
->ValueName
!= NULL
)
441 if (lpFolderData
->bUserShellFolder
)
443 wcscpy(szBuffer
, L
"%ALLUSERSPROFILE%\\");
444 wcscat(szBuffer
, lpFolderData
->Path
);
446 dwLength
= (wcslen (szBuffer
) + 1) * sizeof(WCHAR
);
447 if (RegSetValueExW(hKey
,
448 lpFolderData
->ValueName
,
454 DPRINT1("Error: %lu\n", GetLastError());
466 DPRINT1("Success\n");