From d8ea61531dedf7755b0b489141226edfbb2903dd Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 3 Oct 2004 09:27:22 +0000 Subject: [PATCH] Update a new users private shell folder paths when a new user profile is created. svn path=/trunk/; revision=11164 --- reactos/lib/userenv/internal.h | 10 ++++-- reactos/lib/userenv/profile.c | 13 +++---- reactos/lib/userenv/registry.c | 26 ++++++++++---- reactos/lib/userenv/setup.c | 63 ++++++++++++++++++++++++++++++++-- 4 files changed, 96 insertions(+), 16 deletions(-) diff --git a/reactos/lib/userenv/internal.h b/reactos/lib/userenv/internal.h index 296c213f3df..9e62905f315 100644 --- a/reactos/lib/userenv/internal.h +++ b/reactos/lib/userenv/internal.h @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: internal.h,v 1.9 2004/09/30 20:23:00 ekohl Exp $ +/* $Id: internal.h,v 1.10 2004/10/03 09:27:22 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -98,7 +98,13 @@ AppendSystemPostfix (LPWSTR lpName, /* registry.c */ BOOL -CreateUserHive (LPCWSTR lpKeyName); +CreateUserHive (LPCWSTR lpKeyName, + LPCWSTR lpProfilePath); + +/* setup.c */ +BOOL +UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath, + HKEY hUserKey); #endif /* _INTERNAL_H */ diff --git a/reactos/lib/userenv/profile.c b/reactos/lib/userenv/profile.c index 6c82828ef31..b1ca385b92a 100644 --- a/reactos/lib/userenv/profile.c +++ b/reactos/lib/userenv/profile.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: profile.c,v 1.13 2004/09/30 20:23:00 ekohl Exp $ +/* $Id: profile.c,v 1.14 2004/10/03 09:27:22 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -127,7 +127,7 @@ CreateUserProfileW (PSID Sid, HKEY hKey; NTSTATUS Status; - DPRINT ("CreateUserProfileW() called\n"); + DPRINT("CreateUserProfileW() called\n"); if (RegOpenKeyExW (HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", @@ -282,12 +282,13 @@ CreateUserProfileW (PSID Sid, RegCloseKey (hKey); /* Create user hive name */ - wcscat (szUserProfilePath, L"\\ntuser.dat"); + wcscpy (szBuffer, szUserProfilePath); + wcscat (szBuffer, L"\\ntuser.dat"); /* Create new user hive */ if (RegLoadKeyW (HKEY_USERS, SidString.Buffer, - szUserProfilePath)) + szBuffer)) { DPRINT1("Error: %lu\n", GetLastError()); RtlFreeUnicodeString (&SidString); @@ -295,7 +296,7 @@ CreateUserProfileW (PSID Sid, } /* Initialize user hive */ - if (!CreateUserHive (SidString.Buffer)) + if (!CreateUserHive (SidString.Buffer, szUserProfilePath)) { DPRINT1("Error: %lu\n", GetLastError()); RtlFreeUnicodeString (&SidString); @@ -307,7 +308,7 @@ CreateUserProfileW (PSID Sid, RtlFreeUnicodeString (&SidString); - DPRINT ("CreateUserProfileW() done\n"); + DPRINT("CreateUserProfileW() done\n"); return TRUE; } diff --git a/reactos/lib/userenv/registry.c b/reactos/lib/userenv/registry.c index 25f312efeb3..da8872d715a 100644 --- a/reactos/lib/userenv/registry.c +++ b/reactos/lib/userenv/registry.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: registry.c,v 1.6 2004/09/30 20:23:00 ekohl Exp $ +/* $Id: registry.c,v 1.7 2004/10/03 09:27:22 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -240,11 +240,11 @@ CopyKey (HKEY hDstKey, BOOL -CreateUserHive (LPCWSTR lpKeyName) +CreateUserHive (LPCWSTR lpKeyName, + LPCWSTR lpProfilePath) { HKEY hDefaultKey; HKEY hUserKey; - BOOL bResult; DPRINT ("CreateUserHive(%S) called\n", lpKeyName); @@ -269,8 +269,22 @@ CreateUserHive (LPCWSTR lpKeyName) return FALSE; } - bResult = CopyKey (hUserKey, - hDefaultKey); + if (!CopyKey(hUserKey, hDefaultKey)) + { + DPRINT1 ("Error: %lu\n", GetLastError()); + RegCloseKey (hUserKey); + RegCloseKey (hDefaultKey); + return FALSE; + } + + if (!UpdateUsersShellFolderSettings(lpProfilePath, + hUserKey)) + { + DPRINT1("Error: %lu\n", GetLastError()); + RegCloseKey (hUserKey); + RegCloseKey (hDefaultKey); + return FALSE; + } RegFlushKey (hUserKey); @@ -279,7 +293,7 @@ CreateUserHive (LPCWSTR lpKeyName) DPRINT ("CreateUserHive() done\n"); - return bResult; + return TRUE; } /* EOF */ diff --git a/reactos/lib/userenv/setup.c b/reactos/lib/userenv/setup.c index 45bb29afa9c..8e792ad71b3 100644 --- a/reactos/lib/userenv/setup.c +++ b/reactos/lib/userenv/setup.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: setup.c,v 1.8 2004/10/02 12:31:28 ekohl Exp $ +/* $Id: setup.c,v 1.9 2004/10/03 09:27:22 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -463,7 +463,66 @@ InitializeProfiles (VOID) RegCloseKey(hKey); - DPRINT1("Success\n"); + DPRINT("Success\n"); + + return TRUE; +} + + +BOOL +UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath, + HKEY hUserKey) +{ + WCHAR szBuffer[MAX_PATH]; + DWORD dwLength; + PFOLDERDATA lpFolderData; + HKEY hFoldersKey; + + DPRINT("UpdateUsersShellFolderSettings() called\n"); + + DPRINT("User profile path: %S\n", lpUserProfilePath); + + if (RegOpenKeyExW(hUserKey, + L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", + 0, + KEY_ALL_ACCESS, + &hFoldersKey)) + { + DPRINT1("Error: %lu\n", GetLastError()); + return FALSE; + } + + lpFolderData = &UserShellFolders[0]; + while (lpFolderData->ValueName != NULL) + { + if (lpFolderData->bShellFolder) + { + wcscpy(szBuffer, lpUserProfilePath); + wcscat(szBuffer, L"\\"); + wcscat(szBuffer, lpFolderData->Path); + + DPRINT("%S: %S\n", lpFolderData->ValueName, szBuffer); + + dwLength = (wcslen (szBuffer) + 1) * sizeof(WCHAR); + if (RegSetValueExW(hFoldersKey, + lpFolderData->ValueName, + 0, + REG_SZ, + (LPBYTE)szBuffer, + dwLength)) + { + DPRINT1("Error: %lu\n", GetLastError()); + RegCloseKey(hFoldersKey); + return FALSE; + } + } + + lpFolderData++; + } + + RegCloseKey(hFoldersKey); + + DPRINT("UpdateUsersShellFolderSettings() done\n"); return TRUE; } -- 2.17.1