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 /* GLOBALS ******************************************************************/
18 /* FUNCTIONS ****************************************************************/
22 BuildVolatileEnvironment(
23 IN PWLSESSION Session
,
24 IN HKEY hKeyCurrentUser
)
26 WCHAR szPath
[MAX_PATH
+ 1];
29 WCHAR szEnvKey
[MAX_PATH
];
30 WCHAR szEnvValue
[1024];
36 HKEY hKeyShellFolders
;
40 /* Create the 'Volatile Environment' key */
41 lError
= RegCreateKeyExW(hKeyCurrentUser
,
42 L
"Volatile Environment",
50 if (lError
!= ERROR_SUCCESS
)
52 WARN("WL: RegCreateKeyExW() failed to create the volatile environment key (Error: %ld)\n", lError
);
56 /* Parse the environment variables and add them to the volatile environment key */
57 if (Session
->Profile
->dwType
== WLX_PROFILE_TYPE_V2_0
&&
58 Session
->Profile
->pszEnvironment
!= NULL
)
60 wstr
= Session
->Profile
->pszEnvironment
;
61 while (*wstr
!= UNICODE_NULL
)
63 size
= wcslen(wstr
) + 1;
65 eqptr
= wcschr(wstr
, L
'=');
72 while (iswspace(*endptr
))
75 length
= (SIZE_T
)(endptr
- wstr
+ 1);
77 wcsncpy(szEnvKey
, wstr
, length
);
81 while (iswspace(*eqptr
))
83 wcscpy(szEnvValue
, eqptr
);
85 RegSetValueExW(hKeyVolatileEnv
,
90 (wcslen(szEnvValue
) + 1) * sizeof(WCHAR
));
97 /* Set the 'APPDATA' environment variable */
98 lError
= RegOpenKeyExW(hKeyCurrentUser
,
99 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
103 if (lError
== ERROR_SUCCESS
)
105 dwSize
= (MAX_PATH
+ 1) * sizeof(WCHAR
);
106 lError
= RegQueryValueExW(hKeyShellFolders
,
112 if (lError
== ERROR_SUCCESS
)
114 TRACE("APPDATA path: %S\n", szPath
);
115 RegSetValueExW(hKeyVolatileEnv
,
120 (wcslen(szPath
) + 1) * sizeof(WCHAR
));
123 RegCloseKey(hKeyShellFolders
);
126 RegCloseKey(hKeyVolatileEnv
);
131 CreateUserEnvironment(
132 IN PWLSESSION Session
)
134 HKEY hKeyCurrentUser
;
137 TRACE("WL: CreateUserEnvironment called\n");
139 /* Impersonate the new user */
140 ImpersonateLoggedOnUser(Session
->UserToken
);
142 /* Open the new users HKCU key */
143 lError
= RegOpenCurrentUser(KEY_CREATE_SUB_KEY
,
145 if (lError
== ERROR_SUCCESS
)
147 BuildVolatileEnvironment(Session
,
149 RegCloseKey(hKeyCurrentUser
);
152 /* Revert the impersonation */
155 TRACE("WL: CreateUserEnvironment done\n");