Update a new users private shell folder paths when a new user profile is created.
authorEric Kohl <eric.kohl@reactos.org>
Sun, 3 Oct 2004 09:27:22 +0000 (09:27 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 3 Oct 2004 09:27:22 +0000 (09:27 +0000)
svn path=/trunk/; revision=11164

reactos/lib/userenv/internal.h
reactos/lib/userenv/profile.c
reactos/lib/userenv/registry.c
reactos/lib/userenv/setup.c

index 296c213..9e62905 100644 (file)
@@ -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 */
 
index 6c82828..b1ca385 100644 (file)
@@ -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;
 }
index 25f312e..da8872d 100644 (file)
@@ -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 */
index 45bb29a..8e792ad 100644 (file)
@@ -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;
 }