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 *****************************************************************/
16 #include <wine/debug.h>
18 WINE_DEFAULT_DEBUG_CHANNEL(winlogon
);
20 /* GLOBALS ******************************************************************/
23 /* FUNCTIONS ****************************************************************/
26 BuildVolatileEnvironment(IN PWLSESSION Session
,
27 IN HKEY hKeyCurrentUser
)
29 WCHAR szPath
[MAX_PATH
+ 1];
32 WCHAR szEnvKey
[MAX_PATH
];
33 WCHAR szEnvValue
[1024];
39 HKEY hKeyShellFolders
;
43 /* Create the 'Volatile Environment' key */
44 lError
= RegCreateKeyExW(hKeyCurrentUser
,
45 L
"Volatile Environment",
53 if (lError
!= ERROR_SUCCESS
)
55 WARN("WL: RegCreateKeyExW() failed to create the volatile environment key (Error: %ld)\n", lError
);
59 /* Parse the environment variables and add them to the volatile environment key */
60 if (Session
->Profile
->dwType
== WLX_PROFILE_TYPE_V2_0
&&
61 Session
->Profile
->pszEnvironment
!= NULL
)
63 wstr
= Session
->Profile
->pszEnvironment
;
64 while (*wstr
!= UNICODE_NULL
)
66 size
= wcslen(wstr
) + 1;
68 eqptr
= wcschr(wstr
, L
'=');
75 while (iswspace(*endptr
))
78 length
= (SIZE_T
)(endptr
- wstr
+ 1);
80 wcsncpy(szEnvKey
, wstr
, length
);
84 while (iswspace(*eqptr
))
86 wcscpy(szEnvValue
, eqptr
);
88 RegSetValueExW(hKeyVolatileEnv
,
93 (wcslen(szEnvValue
) + 1) * sizeof(WCHAR
));
100 /* Set the 'APPDATA' environment variable */
101 lError
= RegOpenKeyExW(hKeyCurrentUser
,
102 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
106 if (lError
== ERROR_SUCCESS
)
108 dwSize
= (MAX_PATH
+ 1) * sizeof(WCHAR
);
109 lError
= RegQueryValueExW(hKeyShellFolders
,
115 if (lError
== ERROR_SUCCESS
)
117 TRACE("APPDATA path: %S\n", szPath
);
118 RegSetValueExW(hKeyVolatileEnv
,
123 (wcslen(szPath
) + 1) * sizeof(WCHAR
));
126 RegCloseKey(hKeyShellFolders
);
129 RegCloseKey(hKeyVolatileEnv
);
134 CreateUserEnvironment(IN PWLSESSION Session
)
136 HKEY hKeyCurrentUser
;
139 TRACE("WL: CreateUserEnvironment called\n");
141 /* Impersonate the new user */
142 ImpersonateLoggedOnUser(Session
->UserToken
);
144 /* Open the new users HKCU key */
145 lError
= RegOpenCurrentUser(KEY_CREATE_SUB_KEY
,
147 if (lError
== ERROR_SUCCESS
)
149 BuildVolatileEnvironment(Session
,
151 RegCloseKey(hKeyCurrentUser
);
154 /* Revert the impersonation */
157 TRACE("WL: CreateUserEnvironment done\n");