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 ******************************************************************/
22 typedef HRESULT (WINAPI
*PFSHGETFOLDERPATHW
)(HWND
, int, HANDLE
, DWORD
, LPWSTR
);
25 /* FUNCTIONS ****************************************************************/
28 BuildVolatileEnvironment(IN PWLSESSION Session
,
31 HINSTANCE hShell32
= NULL
;
32 PFSHGETFOLDERPATHW pfSHGetFolderPathW
= NULL
;
33 WCHAR szPath
[MAX_PATH
+ 1];
37 WCHAR szEnvKey
[MAX_PATH
];
38 WCHAR szEnvValue
[1024];
43 if (Session
->Profile
->dwType
== WLX_PROFILE_TYPE_V2_0
&&
44 Session
->Profile
->pszEnvironment
!= NULL
)
46 wstr
= Session
->Profile
->pszEnvironment
;
47 while (*wstr
!= UNICODE_NULL
)
49 size
= wcslen(wstr
) + 1;
51 eqptr
= wcschr(wstr
, L
'=');
58 while (iswspace(*endptr
))
61 length
= (SIZE_T
)(endptr
- wstr
+ 1);
63 wcsncpy(szEnvKey
, wstr
, length
);
67 while (iswspace(*eqptr
))
69 wcscpy(szEnvValue
, eqptr
);
76 (wcslen(szEnvValue
) + 1) * sizeof(WCHAR
));
84 hShell32
= LoadLibraryW(L
"shell32.dll");
87 pfSHGetFolderPathW
= (PFSHGETFOLDERPATHW
)GetProcAddress(hShell32
,
89 if (pfSHGetFolderPathW
!= NULL
)
91 if (pfSHGetFolderPathW(NULL
,
92 CSIDL_APPDATA
| CSIDL_FLAG_DONT_VERIFY
,
102 (wcslen(szPath
) + 1) * sizeof(WCHAR
));
106 FreeLibrary(hShell32
);
112 CreateUserEnvironment(IN PWLSESSION Session
)
117 HKEY hKeyCurrentUser
;
119 TRACE("WL: CreateUserEnvironment called\n");
121 /* Impersonate the new user */
122 ImpersonateLoggedOnUser(Session
->UserToken
);
124 /* Open the new users HKCU key */
125 lError
= RegOpenCurrentUser(KEY_CREATE_SUB_KEY
,
127 if (lError
== ERROR_SUCCESS
)
129 /* Create the 'Volatile Environment' key */
130 lError
= RegCreateKeyExW(hKeyCurrentUser
,
131 L
"Volatile Environment",
139 if (lError
== ERROR_SUCCESS
)
141 BuildVolatileEnvironment(Session
,
148 WARN("WL: RegCreateKeyExW() failed (Error: %ld)\n", lError
);
151 RegCloseKey(hKeyCurrentUser
);
154 /* Revert the impersonation */
157 TRACE("WL: CreateUserEnvironment done\n");