1fb30af4fd96816cbac4578a7f8be6e933ba026c
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Winlogon
4 * FILE: base/system/winlogon/environment.c
5 * PURPOSE: User environment routines
6 * PROGRAMMERS: Thomas Weidenmueller (w3seek@users.sourceforge.net)
7 * Hervé Poussineau (hpoussin@reactos.org)
11 /* INCLUDES *****************************************************************/
15 /* FUNCTIONS ****************************************************************/
19 BuildVolatileEnvironment(
20 IN PWLSESSION Session
,
21 IN HKEY hKeyCurrentUser
)
23 WCHAR szPath
[MAX_PATH
+ 1];
26 WCHAR szEnvKey
[MAX_PATH
];
27 WCHAR szEnvValue
[1024];
33 HKEY hKeyShellFolders
;
37 /* Create the 'Volatile Environment' key */
38 lError
= RegCreateKeyExW(hKeyCurrentUser
,
39 L
"Volatile Environment",
47 if (lError
!= ERROR_SUCCESS
)
49 WARN("WL: RegCreateKeyExW() failed to create the volatile environment key (Error: %ld)\n", lError
);
53 /* Parse the environment variables and add them to the volatile environment key */
54 if (Session
->Profile
->dwType
== WLX_PROFILE_TYPE_V2_0
&&
55 Session
->Profile
->pszEnvironment
!= NULL
)
57 wstr
= Session
->Profile
->pszEnvironment
;
58 while (*wstr
!= UNICODE_NULL
)
60 size
= wcslen(wstr
) + 1;
62 eqptr
= wcschr(wstr
, L
'=');
69 while (iswspace(*endptr
))
72 length
= (SIZE_T
)(endptr
- wstr
+ 1);
74 wcsncpy(szEnvKey
, wstr
, length
);
78 while (iswspace(*eqptr
))
80 wcscpy(szEnvValue
, eqptr
);
82 RegSetValueExW(hKeyVolatileEnv
,
87 (wcslen(szEnvValue
) + 1) * sizeof(WCHAR
));
94 /* Set the 'APPDATA' environment variable */
95 lError
= RegOpenKeyExW(hKeyCurrentUser
,
96 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
100 if (lError
== ERROR_SUCCESS
)
102 dwSize
= (MAX_PATH
+ 1) * sizeof(WCHAR
);
103 lError
= RegQueryValueExW(hKeyShellFolders
,
109 if (lError
== ERROR_SUCCESS
)
111 TRACE("APPDATA path: %S\n", szPath
);
112 RegSetValueExW(hKeyVolatileEnv
,
117 (wcslen(szPath
) + 1) * sizeof(WCHAR
));
120 RegCloseKey(hKeyShellFolders
);
123 RegCloseKey(hKeyVolatileEnv
);
128 CreateUserEnvironment(
129 IN PWLSESSION Session
)
131 HKEY hKeyCurrentUser
;
134 TRACE("WL: CreateUserEnvironment called\n");
136 /* Impersonate the new user */
137 ImpersonateLoggedOnUser(Session
->UserToken
);
139 /* Open the new users HKCU key */
140 lError
= RegOpenCurrentUser(KEY_CREATE_SUB_KEY
,
142 if (lError
== ERROR_SUCCESS
)
144 BuildVolatileEnvironment(Session
,
146 RegCloseKey(hKeyCurrentUser
);
149 /* Revert the impersonation */
152 TRACE("WL: CreateUserEnvironment done\n");