mirror of
https://github.com/reactos/reactos.git
synced 2025-05-20 17:45:06 +00:00
[WINLOGON]
- Set the APPDATA environment variable without loading shell32.dll. This should fix bug #5398. svn path=/trunk/; revision=47324
This commit is contained in:
parent
89b45a7e71
commit
dcc025f6e3
1 changed files with 52 additions and 61 deletions
|
@ -19,25 +19,42 @@ WINE_DEFAULT_DEBUG_CHANNEL(winlogon);
|
||||||
|
|
||||||
/* GLOBALS ******************************************************************/
|
/* GLOBALS ******************************************************************/
|
||||||
|
|
||||||
typedef HRESULT (WINAPI *PFSHGETFOLDERPATHW)(HWND, int, HANDLE, DWORD, LPWSTR);
|
|
||||||
|
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
BuildVolatileEnvironment(IN PWLSESSION Session,
|
BuildVolatileEnvironment(IN PWLSESSION Session,
|
||||||
IN HKEY hKey)
|
IN HKEY hKeyCurrentUser)
|
||||||
{
|
{
|
||||||
HINSTANCE hShell32 = NULL;
|
|
||||||
PFSHGETFOLDERPATHW pfSHGetFolderPathW = NULL;
|
|
||||||
WCHAR szPath[MAX_PATH + 1];
|
WCHAR szPath[MAX_PATH + 1];
|
||||||
WCHAR szExpandedPath[MAX_PATH + 1];
|
|
||||||
LPCWSTR wstr;
|
LPCWSTR wstr;
|
||||||
SIZE_T size;
|
SIZE_T size;
|
||||||
WCHAR szEnvKey[MAX_PATH];
|
WCHAR szEnvKey[MAX_PATH];
|
||||||
WCHAR szEnvValue[1024];
|
WCHAR szEnvValue[1024];
|
||||||
SIZE_T length;
|
SIZE_T length;
|
||||||
LPWSTR eqptr, endptr;
|
LPWSTR eqptr, endptr;
|
||||||
|
DWORD dwDisp;
|
||||||
|
LONG lError;
|
||||||
|
HKEY hKeyVolatileEnv;
|
||||||
|
HKEY hKeyShellFolders;
|
||||||
|
DWORD dwType;
|
||||||
|
DWORD dwSize;
|
||||||
|
|
||||||
|
/* Create the 'Volatile Environment' key */
|
||||||
|
lError = RegCreateKeyExW(hKeyCurrentUser,
|
||||||
|
L"Volatile Environment",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
REG_OPTION_VOLATILE,
|
||||||
|
KEY_WRITE,
|
||||||
|
NULL,
|
||||||
|
&hKeyVolatileEnv,
|
||||||
|
&dwDisp);
|
||||||
|
if (lError != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
WARN("WL: RegCreateKeyExW() failed to create the volatile environment key (Error: %ld)\n", lError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse the environment variables and add them to the volatile environment key */
|
/* Parse the environment variables and add them to the volatile environment key */
|
||||||
if (Session->Profile->dwType == WLX_PROFILE_TYPE_V2_0 &&
|
if (Session->Profile->dwType == WLX_PROFILE_TYPE_V2_0 &&
|
||||||
|
@ -68,7 +85,7 @@ BuildVolatileEnvironment(IN PWLSESSION Session,
|
||||||
eqptr++;
|
eqptr++;
|
||||||
wcscpy(szEnvValue, eqptr);
|
wcscpy(szEnvValue, eqptr);
|
||||||
|
|
||||||
RegSetValueExW(hKey,
|
RegSetValueExW(hKeyVolatileEnv,
|
||||||
szEnvKey,
|
szEnvKey,
|
||||||
0,
|
0,
|
||||||
REG_SZ,
|
REG_SZ,
|
||||||
|
@ -80,50 +97,44 @@ BuildVolatileEnvironment(IN PWLSESSION Session,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load shell32.dll and call SHGetFolderPathW to get the users appdata folder path */
|
/* Set the 'APPDATA' environment variable */
|
||||||
hShell32 = LoadLibraryW(L"shell32.dll");
|
lError = RegOpenKeyExW(hKeyCurrentUser,
|
||||||
if (hShell32 != NULL)
|
L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
|
||||||
|
0,
|
||||||
|
KEY_READ,
|
||||||
|
&hKeyShellFolders);
|
||||||
|
if (lError == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
pfSHGetFolderPathW = (PFSHGETFOLDERPATHW)GetProcAddress(hShell32,
|
dwSize = (MAX_PATH + 1) * sizeof(WCHAR);
|
||||||
"SHGetFolderPathW");
|
lError = RegQueryValueExW(hKeyShellFolders,
|
||||||
if (pfSHGetFolderPathW != NULL)
|
L"AppData",
|
||||||
|
NULL,
|
||||||
|
&dwType,
|
||||||
|
(LPBYTE)szPath,
|
||||||
|
&dwSize);
|
||||||
|
if (lError == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
if (pfSHGetFolderPathW(NULL,
|
TRACE("APPDATA path: %S\n", szPath);
|
||||||
CSIDL_APPDATA | CSIDL_FLAG_DONT_VERIFY,
|
RegSetValueExW(hKeyVolatileEnv,
|
||||||
Session->UserToken,
|
L"APPDATA",
|
||||||
0,
|
0,
|
||||||
szPath) == S_OK)
|
REG_SZ,
|
||||||
{
|
(LPBYTE)szPath,
|
||||||
/* FIXME: Expand %USERPROFILE% here. SHGetFolderPathW should do it for us. See Bug #5372.*/
|
(wcslen(szPath) + 1) * sizeof(WCHAR));
|
||||||
TRACE("APPDATA path: %S\n", szPath);
|
|
||||||
ExpandEnvironmentStringsForUserW(Session->UserToken,
|
|
||||||
szPath,
|
|
||||||
szExpandedPath,
|
|
||||||
MAX_PATH);
|
|
||||||
|
|
||||||
/* Add the appdata folder path to the users volatile environment key */
|
|
||||||
TRACE("APPDATA expanded path: %S\n", szExpandedPath);
|
|
||||||
RegSetValueExW(hKey,
|
|
||||||
L"APPDATA",
|
|
||||||
0,
|
|
||||||
REG_SZ,
|
|
||||||
(LPBYTE)szExpandedPath,
|
|
||||||
(wcslen(szExpandedPath) + 1) * sizeof(WCHAR));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FreeLibrary(hShell32);
|
RegCloseKey(hKeyShellFolders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegCloseKey(hKeyVolatileEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
CreateUserEnvironment(IN PWLSESSION Session)
|
CreateUserEnvironment(IN PWLSESSION Session)
|
||||||
{
|
{
|
||||||
HKEY hKey;
|
|
||||||
DWORD dwDisp;
|
|
||||||
LONG lError;
|
|
||||||
HKEY hKeyCurrentUser;
|
HKEY hKeyCurrentUser;
|
||||||
|
LONG lError;
|
||||||
|
|
||||||
TRACE("WL: CreateUserEnvironment called\n");
|
TRACE("WL: CreateUserEnvironment called\n");
|
||||||
|
|
||||||
|
@ -135,28 +146,8 @@ CreateUserEnvironment(IN PWLSESSION Session)
|
||||||
&hKeyCurrentUser);
|
&hKeyCurrentUser);
|
||||||
if (lError == ERROR_SUCCESS)
|
if (lError == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
/* Create the 'Volatile Environment' key */
|
BuildVolatileEnvironment(Session,
|
||||||
lError = RegCreateKeyExW(hKeyCurrentUser,
|
hKeyCurrentUser);
|
||||||
L"Volatile Environment",
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
REG_OPTION_VOLATILE,
|
|
||||||
KEY_WRITE,
|
|
||||||
NULL,
|
|
||||||
&hKey,
|
|
||||||
&dwDisp);
|
|
||||||
if (lError == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
BuildVolatileEnvironment(Session,
|
|
||||||
hKey);
|
|
||||||
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
WARN("WL: RegCreateKeyExW() failed (Error: %ld)\n", lError);
|
|
||||||
}
|
|
||||||
|
|
||||||
RegCloseKey(hKeyCurrentUser);
|
RegCloseKey(hKeyCurrentUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue