[USERENV]
authorEric Kohl <eric.kohl@reactos.org>
Fri, 7 May 2010 00:17:04 +0000 (00:17 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Fri, 7 May 2010 00:17:04 +0000 (00:17 +0000)
- Create the environment variables 'ProgramFiles' and 'CommonProgramFiles' from the registry.

Fixes bug #4008.
See issue #2972 for more details.

svn path=/trunk/; revision=47116

reactos/dll/win32/userenv/environment.c

index 16754d4..5bb38a6 100644 (file)
@@ -317,9 +317,13 @@ CreateEnvironmentBlock(LPVOID *lpEnvironment,
                        BOOL bInherit)
 {
     WCHAR Buffer[MAX_PATH];
                        BOOL bInherit)
 {
     WCHAR Buffer[MAX_PATH];
+    WCHAR szValue[1024];
     DWORD Length;
     DWORD Length;
+    DWORD dwType;
+    HKEY hKey;
     HKEY hKeyUser;
     NTSTATUS Status;
     HKEY hKeyUser;
     NTSTATUS Status;
+    LONG lError;
 
     DPRINT("CreateEnvironmentBlock() called\n");
 
 
     DPRINT("CreateEnvironmentBlock() called\n");
 
@@ -349,17 +353,6 @@ CreateEnvironmentBlock(LPVOID *lpEnvironment,
                                    FALSE);
     }
 
                                    FALSE);
     }
 
-    if (hToken == NULL)
-        return TRUE;
-
-    hKeyUser = GetCurrentUserKey(hToken);
-    if (hKeyUser == NULL)
-    {
-        DPRINT1("GetCurrentUserKey() failed\n");
-        RtlDestroyEnvironment(*lpEnvironment);
-        return FALSE;
-    }
-
     /* Set 'ALLUSERSPROFILE' variable */
     Length = MAX_PATH;
     if (GetAllUsersProfileDirectoryW(Buffer,
     /* Set 'ALLUSERSPROFILE' variable */
     Length = MAX_PATH;
     if (GetAllUsersProfileDirectoryW(Buffer,
@@ -371,6 +364,57 @@ CreateEnvironmentBlock(LPVOID *lpEnvironment,
                                    FALSE);
     }
 
                                    FALSE);
     }
 
+    lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                           L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
+                           0,
+                           KEY_READ,
+                           &hKey);
+    if (lError == ERROR_SUCCESS)
+    {
+        Length = 1024 * sizeof(WCHAR);
+        lError = RegQueryValueExW(hKey,
+                                  L"ProgramFilesDir",
+                                  NULL,
+                                  &dwType,
+                                  (LPBYTE)szValue,
+                                  &Length);
+        if (lError == ERROR_SUCCESS)
+        {
+            SetUserEnvironmentVariable(lpEnvironment,
+                                       L"ProgramFiles",
+                                       szValue,
+                                       FALSE);
+        }
+
+        Length = 1024 * sizeof(WCHAR);
+        lError = RegQueryValueExW(hKey,
+                                  L"CommonFilesDir",
+                                  NULL,
+                                  &dwType,
+                                  (LPBYTE)szValue,
+                                  &Length);
+        if (lError == ERROR_SUCCESS)
+        {
+            SetUserEnvironmentVariable(lpEnvironment,
+                                       L"CommonProgramFiles",
+                                       szValue,
+                                       FALSE);
+        }
+
+        RegCloseKey(hKey);
+    }
+
+    if (hToken == NULL)
+        return TRUE;
+
+    hKeyUser = GetCurrentUserKey(hToken);
+    if (hKeyUser == NULL)
+    {
+        DPRINT1("GetCurrentUserKey() failed\n");
+        RtlDestroyEnvironment(*lpEnvironment);
+        return FALSE;
+    }
+
     /* Set 'USERPROFILE' variable */
     Length = MAX_PATH;
     if (GetUserProfileDirectoryW(hToken,
     /* Set 'USERPROFILE' variable */
     Length = MAX_PATH;
     if (GetUserProfileDirectoryW(hToken,