2004-09-30 20:23:00 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2004 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-09-30 20:23:00 +00:00
|
|
|
*/
|
2013-03-16 20:41:13 +00:00
|
|
|
/*
|
2004-03-19 12:40:49 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
2013-10-24 20:16:20 +00:00
|
|
|
* FILE: dll/win32/userenv/environment.c
|
2004-03-19 12:40:49 +00:00
|
|
|
* PURPOSE: User environment functions
|
|
|
|
* PROGRAMMER: Eric Kohl
|
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "precomp.h"
|
2004-03-19 12:40:49 +00:00
|
|
|
|
2006-01-11 22:40:31 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
static
|
|
|
|
BOOL
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(PWSTR* Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
LPWSTR lpName,
|
|
|
|
LPWSTR lpValue,
|
|
|
|
BOOL bExpand)
|
2004-03-19 12:40:49 +00:00
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
NTSTATUS Status;
|
2010-05-05 22:53:01 +00:00
|
|
|
UNICODE_STRING Name;
|
2016-12-08 16:12:59 +00:00
|
|
|
UNICODE_STRING SrcValue, DstValue;
|
2010-05-05 22:53:01 +00:00
|
|
|
ULONG Length;
|
|
|
|
PVOID Buffer = NULL;
|
2016-12-08 16:08:59 +00:00
|
|
|
WCHAR ShortName[MAX_PATH];
|
2010-05-05 22:53:01 +00:00
|
|
|
|
|
|
|
if (bExpand)
|
2004-03-19 12:40:49 +00:00
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
RtlInitUnicodeString(&SrcValue, lpValue);
|
2010-05-05 22:53:01 +00:00
|
|
|
|
|
|
|
Length = 2 * MAX_PATH * sizeof(WCHAR);
|
|
|
|
|
|
|
|
DstValue.Length = 0;
|
|
|
|
DstValue.MaximumLength = Length;
|
2016-12-08 16:08:59 +00:00
|
|
|
DstValue.Buffer = Buffer = LocalAlloc(LPTR, Length);
|
2010-05-05 22:53:01 +00:00
|
|
|
if (DstValue.Buffer == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("LocalAlloc() failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
Status = RtlExpandEnvironmentStrings_U(*Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
&SrcValue,
|
|
|
|
&DstValue,
|
|
|
|
&Length);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("RtlExpandEnvironmentStrings_U() failed (Status %lx)\n", Status);
|
|
|
|
DPRINT1("Length %lu\n", Length);
|
2016-12-08 16:08:59 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
if (Buffer)
|
|
|
|
LocalFree(Buffer);
|
2016-12-08 16:08:59 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-19 12:40:49 +00:00
|
|
|
}
|
2010-05-05 22:53:01 +00:00
|
|
|
else
|
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
RtlInitUnicodeString(&DstValue, lpValue);
|
2010-05-05 22:53:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
if (!_wcsicmp(lpName, L"TEMP") || !_wcsicmp(lpName, L"TMP"))
|
2010-05-05 22:53:01 +00:00
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
if (GetShortPathNameW(DstValue.Buffer, ShortName, ARRAYSIZE(ShortName)))
|
2010-05-05 22:53:01 +00:00
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
RtlInitUnicodeString(&DstValue, ShortName);
|
2010-05-05 22:53:01 +00:00
|
|
|
}
|
2016-12-08 16:12:59 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT("GetShortPathNameW() failed for %S (Error %lu)\n", DstValue.Buffer, GetLastError());
|
|
|
|
}
|
2010-05-05 22:53:01 +00:00
|
|
|
|
|
|
|
DPRINT("Buffer: %S\n", ShortName);
|
|
|
|
}
|
|
|
|
|
2016-12-08 16:08:59 +00:00
|
|
|
RtlInitUnicodeString(&Name, lpName);
|
2010-05-05 22:53:01 +00:00
|
|
|
|
|
|
|
DPRINT("Value: %wZ\n", &DstValue);
|
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
Status = RtlSetEnvironmentVariable(Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
&Name,
|
|
|
|
&DstValue);
|
|
|
|
|
|
|
|
if (Buffer)
|
|
|
|
LocalFree(Buffer);
|
2004-03-19 12:40:49 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("RtlSetEnvironmentVariable() failed (Status %lx)\n", Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2004-03-19 12:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
static
|
|
|
|
BOOL
|
2016-12-08 16:12:59 +00:00
|
|
|
AppendUserEnvironmentVariable(PWSTR* Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
LPWSTR lpName,
|
|
|
|
LPWSTR lpValue)
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
NTSTATUS Status;
|
2016-12-08 16:12:59 +00:00
|
|
|
UNICODE_STRING Name, Value;
|
2010-05-05 22:53:01 +00:00
|
|
|
|
2016-12-08 16:08:59 +00:00
|
|
|
RtlInitUnicodeString(&Name, lpName);
|
2010-05-05 22:53:01 +00:00
|
|
|
|
|
|
|
Value.Length = 0;
|
|
|
|
Value.MaximumLength = 1024 * sizeof(WCHAR);
|
2016-12-08 16:08:59 +00:00
|
|
|
Value.Buffer = LocalAlloc(LPTR, Value.MaximumLength);
|
2010-05-05 22:53:01 +00:00
|
|
|
if (Value.Buffer == NULL)
|
|
|
|
return FALSE;
|
2016-12-08 16:08:59 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
Value.Buffer[0] = UNICODE_NULL;
|
2004-03-24 16:00:01 +00:00
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
Status = RtlQueryEnvironmentVariable_U(*Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
&Name,
|
|
|
|
&Value);
|
|
|
|
if (NT_SUCCESS(Status))
|
2016-12-08 16:08:59 +00:00
|
|
|
RtlAppendUnicodeToString(&Value, L";");
|
2004-03-24 16:00:01 +00:00
|
|
|
|
2016-12-08 16:08:59 +00:00
|
|
|
RtlAppendUnicodeToString(&Value, lpValue);
|
2004-03-24 16:00:01 +00:00
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
Status = RtlSetEnvironmentVariable(Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
&Name,
|
|
|
|
&Value);
|
|
|
|
LocalFree(Value.Buffer);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
DPRINT1("RtlSetEnvironmentVariable() failed (Status %lx)\n", Status);
|
|
|
|
return FALSE;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
return TRUE;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
static
|
|
|
|
HKEY
|
2010-05-05 22:53:01 +00:00
|
|
|
GetCurrentUserKey(HANDLE hToken)
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
LONG Error;
|
2010-05-05 22:53:01 +00:00
|
|
|
UNICODE_STRING SidString;
|
|
|
|
HKEY hKey;
|
2004-03-24 16:00:01 +00:00
|
|
|
|
2016-12-08 16:08:59 +00:00
|
|
|
if (!GetUserSidStringFromToken(hToken, &SidString))
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
DPRINT1("GetUserSidFromToken() failed\n");
|
|
|
|
return NULL;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
Error = RegOpenKeyExW(HKEY_USERS,
|
|
|
|
SidString.Buffer,
|
|
|
|
0,
|
|
|
|
MAXIMUM_ALLOWED,
|
|
|
|
&hKey);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error);
|
|
|
|
RtlFreeUnicodeString(&SidString);
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
return NULL;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
RtlFreeUnicodeString(&SidString);
|
2004-03-24 16:00:01 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
return hKey;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-02 14:45:26 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
GetUserAndDomainName(IN HANDLE hToken,
|
|
|
|
OUT LPWSTR *UserName,
|
|
|
|
OUT LPWSTR *DomainName)
|
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
BOOL bRet = TRUE;
|
2013-11-02 14:45:26 +00:00
|
|
|
PSID Sid = NULL;
|
|
|
|
LPWSTR lpUserName = NULL;
|
|
|
|
LPWSTR lpDomainName = NULL;
|
|
|
|
DWORD cbUserName = 0;
|
|
|
|
DWORD cbDomainName = 0;
|
|
|
|
SID_NAME_USE SidNameUse;
|
|
|
|
|
2016-07-31 13:46:23 +00:00
|
|
|
Sid = GetUserSid(hToken);
|
|
|
|
if (Sid == NULL)
|
2013-11-02 14:45:26 +00:00
|
|
|
{
|
2016-07-31 13:46:23 +00:00
|
|
|
DPRINT1("GetUserSid() failed\n");
|
2013-11-02 14:45:26 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LookupAccountSidW(NULL,
|
|
|
|
Sid,
|
|
|
|
NULL,
|
|
|
|
&cbUserName,
|
|
|
|
NULL,
|
|
|
|
&cbDomainName,
|
|
|
|
&SidNameUse))
|
|
|
|
{
|
|
|
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
{
|
|
|
|
bRet = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-08 16:08:59 +00:00
|
|
|
lpUserName = LocalAlloc(LPTR, cbUserName * sizeof(WCHAR));
|
2013-11-02 14:45:26 +00:00
|
|
|
if (lpUserName == NULL)
|
|
|
|
{
|
|
|
|
bRet = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-12-08 16:08:59 +00:00
|
|
|
lpDomainName = LocalAlloc(LPTR, cbDomainName * sizeof(WCHAR));
|
2013-11-02 14:45:26 +00:00
|
|
|
if (lpDomainName == NULL)
|
|
|
|
{
|
|
|
|
bRet = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LookupAccountSidW(NULL,
|
|
|
|
Sid,
|
|
|
|
lpUserName,
|
|
|
|
&cbUserName,
|
|
|
|
lpDomainName,
|
|
|
|
&cbDomainName,
|
|
|
|
&SidNameUse))
|
|
|
|
{
|
|
|
|
bRet = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
*UserName = lpUserName;
|
|
|
|
*DomainName = lpDomainName;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (bRet == FALSE)
|
|
|
|
{
|
|
|
|
if (lpUserName != NULL)
|
|
|
|
LocalFree(lpUserName);
|
|
|
|
|
|
|
|
if (lpDomainName != NULL)
|
|
|
|
LocalFree(lpDomainName);
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalFree(Sid);
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
static
|
|
|
|
BOOL
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironment(PWSTR* Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
HKEY hKey,
|
|
|
|
LPWSTR lpSubKeyName)
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
LONG Error;
|
2010-05-05 22:53:01 +00:00
|
|
|
HKEY hEnvKey;
|
|
|
|
DWORD dwValues;
|
|
|
|
DWORD dwMaxValueNameLength;
|
|
|
|
DWORD dwMaxValueDataLength;
|
|
|
|
DWORD dwValueNameLength;
|
|
|
|
DWORD dwValueDataLength;
|
|
|
|
DWORD dwType;
|
|
|
|
DWORD i;
|
|
|
|
LPWSTR lpValueName;
|
|
|
|
LPWSTR lpValueData;
|
|
|
|
|
|
|
|
Error = RegOpenKeyExW(hKey,
|
|
|
|
lpSubKeyName,
|
|
|
|
0,
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
&hEnvKey);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error);
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
return FALSE;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
Error = RegQueryInfoKey(hEnvKey,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&dwValues,
|
|
|
|
&dwMaxValueNameLength,
|
|
|
|
&dwMaxValueDataLength,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
DPRINT1("RegQueryInforKey() failed (Error %ld)\n", Error);
|
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
return FALSE;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
if (dwValues == 0)
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
return TRUE;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
/* Allocate buffers */
|
2015-04-26 04:10:25 +00:00
|
|
|
dwMaxValueNameLength++;
|
2016-12-08 16:08:59 +00:00
|
|
|
lpValueName = LocalAlloc(LPTR, dwMaxValueNameLength * sizeof(WCHAR));
|
2010-05-05 22:53:01 +00:00
|
|
|
if (lpValueName == NULL)
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
return FALSE;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 16:08:59 +00:00
|
|
|
lpValueData = LocalAlloc(LPTR, dwMaxValueDataLength);
|
2010-05-05 22:53:01 +00:00
|
|
|
if (lpValueData == NULL)
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
LocalFree(lpValueName);
|
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
return FALSE;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
/* Enumerate values */
|
|
|
|
for (i = 0; i < dwValues; i++)
|
2004-03-24 16:00:01 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
dwValueNameLength = dwMaxValueNameLength;
|
|
|
|
dwValueDataLength = dwMaxValueDataLength;
|
2016-07-31 13:46:23 +00:00
|
|
|
|
|
|
|
Error = RegEnumValueW(hEnvKey,
|
|
|
|
i,
|
|
|
|
lpValueName,
|
|
|
|
&dwValueNameLength,
|
|
|
|
NULL,
|
|
|
|
&dwType,
|
|
|
|
(LPBYTE)lpValueData,
|
|
|
|
&dwValueDataLength);
|
|
|
|
if (Error == ERROR_SUCCESS)
|
2010-05-05 22:53:01 +00:00
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
if (!_wcsicmp(lpValueName, L"PATH"))
|
2016-07-31 13:46:23 +00:00
|
|
|
{
|
|
|
|
/* Append 'Path' environment variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
AppendUserEnvironmentVariable(Environment,
|
2016-07-31 13:46:23 +00:00
|
|
|
lpValueName,
|
|
|
|
lpValueData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Set environment variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2016-07-31 13:46:23 +00:00
|
|
|
lpValueName,
|
|
|
|
lpValueData,
|
|
|
|
(dwType == REG_EXPAND_SZ));
|
|
|
|
}
|
2010-05-05 22:53:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 13:46:23 +00:00
|
|
|
LocalFree(lpValueData);
|
|
|
|
LocalFree(lpValueName);
|
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
|
|
|
|
return FALSE;
|
2010-05-05 22:53:01 +00:00
|
|
|
}
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
LocalFree(lpValueData);
|
|
|
|
LocalFree(lpValueName);
|
|
|
|
RegCloseKey(hEnvKey);
|
2004-03-24 16:00:01 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
return TRUE;
|
2004-03-24 16:00:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-01 14:26:12 +00:00
|
|
|
static
|
|
|
|
BOOL
|
2016-12-08 16:12:59 +00:00
|
|
|
SetSystemEnvironment(PWSTR* Environment)
|
2016-08-01 14:26:12 +00:00
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
LONG Error;
|
2016-08-01 14:26:12 +00:00
|
|
|
HKEY hEnvKey;
|
|
|
|
DWORD dwValues;
|
|
|
|
DWORD dwMaxValueNameLength;
|
|
|
|
DWORD dwMaxValueDataLength;
|
|
|
|
DWORD dwValueNameLength;
|
|
|
|
DWORD dwValueDataLength;
|
|
|
|
DWORD dwType;
|
|
|
|
DWORD i;
|
|
|
|
LPWSTR lpValueName;
|
|
|
|
LPWSTR lpValueData;
|
|
|
|
|
|
|
|
Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
|
|
|
|
0,
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
&hEnvKey);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error = RegQueryInfoKey(hEnvKey,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&dwValues,
|
|
|
|
&dwMaxValueNameLength,
|
|
|
|
&dwMaxValueDataLength,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
DPRINT1("RegQueryInforKey() failed (Error %ld)\n", Error);
|
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dwValues == 0)
|
|
|
|
{
|
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate buffers */
|
|
|
|
dwMaxValueNameLength++;
|
2016-12-08 16:08:59 +00:00
|
|
|
lpValueName = LocalAlloc(LPTR, dwMaxValueNameLength * sizeof(WCHAR));
|
2016-08-01 14:26:12 +00:00
|
|
|
if (lpValueName == NULL)
|
|
|
|
{
|
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-12-08 16:08:59 +00:00
|
|
|
lpValueData = LocalAlloc(LPTR, dwMaxValueDataLength);
|
2016-08-01 14:26:12 +00:00
|
|
|
if (lpValueData == NULL)
|
|
|
|
{
|
|
|
|
LocalFree(lpValueName);
|
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enumerate values */
|
|
|
|
for (i = 0; i < dwValues; i++)
|
|
|
|
{
|
|
|
|
dwValueNameLength = dwMaxValueNameLength;
|
|
|
|
dwValueDataLength = dwMaxValueDataLength;
|
|
|
|
|
|
|
|
Error = RegEnumValueW(hEnvKey,
|
|
|
|
i,
|
|
|
|
lpValueName,
|
|
|
|
&dwValueNameLength,
|
|
|
|
NULL,
|
|
|
|
&dwType,
|
|
|
|
(LPBYTE)lpValueData,
|
|
|
|
&dwValueDataLength);
|
|
|
|
if (Error == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
/* Set environment variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2016-08-01 14:26:12 +00:00
|
|
|
lpValueName,
|
|
|
|
lpValueData,
|
|
|
|
(dwType == REG_EXPAND_SZ));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LocalFree(lpValueData);
|
|
|
|
LocalFree(lpValueName);
|
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalFree(lpValueData);
|
|
|
|
LocalFree(lpValueName);
|
|
|
|
RegCloseKey(hEnvKey);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2016-12-08 16:12:59 +00:00
|
|
|
CreateEnvironmentBlock(OUT LPVOID *lpEnvironment,
|
|
|
|
IN HANDLE hToken,
|
|
|
|
IN BOOL bInherit)
|
2004-03-19 12:40:49 +00:00
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
LONG lError;
|
2016-12-08 16:12:59 +00:00
|
|
|
PWSTR* Environment = (PWSTR*)lpEnvironment;
|
2010-05-05 22:53:01 +00:00
|
|
|
DWORD Length;
|
2010-05-07 00:17:04 +00:00
|
|
|
DWORD dwType;
|
|
|
|
HKEY hKey;
|
2010-05-05 22:53:01 +00:00
|
|
|
HKEY hKeyUser;
|
2013-11-02 14:45:26 +00:00
|
|
|
LPWSTR lpUserName = NULL;
|
|
|
|
LPWSTR lpDomainName = NULL;
|
2016-12-08 16:08:59 +00:00
|
|
|
WCHAR Buffer[MAX_PATH];
|
|
|
|
WCHAR szValue[1024];
|
2004-03-19 12:40:49 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
DPRINT("CreateEnvironmentBlock() called\n");
|
2004-03-19 12:40:49 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
if (lpEnvironment == NULL)
|
2006-01-12 00:11:14 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
2006-01-12 00:11:14 +00:00
|
|
|
}
|
2004-03-19 12:40:49 +00:00
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
Status = RtlCreateEnvironment((BOOLEAN)bInherit, Environment);
|
2016-08-01 14:26:12 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2004-03-19 12:40:49 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
DPRINT1("RtlCreateEnvironment() failed (Status %lx)\n", Status);
|
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
return FALSE;
|
2004-03-19 12:40:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-07 16:40:33 +00:00
|
|
|
/* Set 'SystemRoot' variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
Length = ARRAYSIZE(Buffer);
|
|
|
|
if (GetEnvironmentVariableW(L"SystemRoot", Buffer, Length))
|
2015-11-07 16:40:33 +00:00
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2015-11-07 16:40:33 +00:00
|
|
|
L"SystemRoot",
|
|
|
|
Buffer,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set 'SystemDrive' variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
if (GetEnvironmentVariableW(L"SystemDrive", Buffer, Length))
|
2015-11-07 16:40:33 +00:00
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2015-11-07 16:40:33 +00:00
|
|
|
L"SystemDrive",
|
|
|
|
Buffer,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
2016-08-01 11:29:01 +00:00
|
|
|
/* Set variables from Session Manager */
|
2016-12-08 16:12:59 +00:00
|
|
|
if (!SetSystemEnvironment(Environment))
|
2016-08-01 14:26:12 +00:00
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
RtlDestroyEnvironment(*Environment);
|
2016-08-01 14:26:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-07-31 13:46:23 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
/* Set 'COMPUTERNAME' variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
Length = ARRAYSIZE(Buffer);
|
|
|
|
if (GetComputerNameW(Buffer, &Length))
|
2004-03-19 12:40:49 +00:00
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
L"COMPUTERNAME",
|
|
|
|
Buffer,
|
|
|
|
FALSE);
|
2004-03-19 12:40:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
/* Set 'ALLUSERSPROFILE' variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
Length = ARRAYSIZE(Buffer);
|
|
|
|
if (GetAllUsersProfileDirectoryW(Buffer, &Length))
|
2004-05-01 11:55:38 +00:00
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
L"ALLUSERSPROFILE",
|
|
|
|
Buffer,
|
|
|
|
FALSE);
|
2004-05-01 11:55:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
/* Set 'USERPROFILE' variable to the default users profile */
|
|
|
|
Length = ARRAYSIZE(Buffer);
|
|
|
|
if (GetDefaultUserProfileDirectoryW(Buffer, &Length))
|
2015-11-07 16:40:33 +00:00
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2015-11-07 16:40:33 +00:00
|
|
|
L"USERPROFILE",
|
|
|
|
Buffer,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
2010-05-07 00:17:04 +00:00
|
|
|
lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
|
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&hKey);
|
|
|
|
if (lError == ERROR_SUCCESS)
|
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
Length = sizeof(szValue);
|
2010-05-07 00:17:04 +00:00
|
|
|
lError = RegQueryValueExW(hKey,
|
|
|
|
L"ProgramFilesDir",
|
|
|
|
NULL,
|
|
|
|
&dwType,
|
|
|
|
(LPBYTE)szValue,
|
|
|
|
&Length);
|
|
|
|
if (lError == ERROR_SUCCESS)
|
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2010-05-07 00:17:04 +00:00
|
|
|
L"ProgramFiles",
|
|
|
|
szValue,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
Length = sizeof(szValue);
|
2010-05-07 00:17:04 +00:00
|
|
|
lError = RegQueryValueExW(hKey,
|
|
|
|
L"CommonFilesDir",
|
|
|
|
NULL,
|
|
|
|
&dwType,
|
|
|
|
(LPBYTE)szValue,
|
|
|
|
&Length);
|
|
|
|
if (lError == ERROR_SUCCESS)
|
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2010-05-07 00:17:04 +00:00
|
|
|
L"CommonProgramFiles",
|
|
|
|
szValue,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
/*
|
|
|
|
* If no user token is specified, the system environment variables are set
|
|
|
|
* and we stop here, otherwise continue setting the user-specific variables.
|
|
|
|
*/
|
2010-05-07 00:17:04 +00:00
|
|
|
if (hToken == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
hKeyUser = GetCurrentUserKey(hToken);
|
|
|
|
if (hKeyUser == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("GetCurrentUserKey() failed\n");
|
2016-12-08 16:12:59 +00:00
|
|
|
RtlDestroyEnvironment(*Environment);
|
2010-05-07 00:17:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
/* Set 'USERPROFILE' variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
Length = ARRAYSIZE(Buffer);
|
2016-12-08 16:08:59 +00:00
|
|
|
if (GetUserProfileDirectoryW(hToken, Buffer, &Length))
|
2004-03-19 12:40:49 +00:00
|
|
|
{
|
2015-06-26 18:59:25 +00:00
|
|
|
DWORD MinLen = 2;
|
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
L"USERPROFILE",
|
|
|
|
Buffer,
|
|
|
|
FALSE);
|
2015-06-26 18:59:25 +00:00
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
// FIXME: Strangely enough the following two environment variables
|
|
|
|
// are not set by userenv.dll in Windows... See r68284 / CORE-9875
|
|
|
|
// FIXME2: This is done by msgina.dll !!
|
|
|
|
|
2015-06-26 18:59:25 +00:00
|
|
|
/* At least <drive letter>:<path> */
|
|
|
|
if (Length > MinLen)
|
|
|
|
{
|
|
|
|
/* Set 'HOMEDRIVE' variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
StringCchCopyNW(szValue, ARRAYSIZE(Buffer), Buffer, MinLen);
|
|
|
|
SetUserEnvironmentVariable(Environment,
|
2015-06-26 18:59:25 +00:00
|
|
|
L"HOMEDRIVE",
|
|
|
|
szValue,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
/* Set 'HOMEPATH' variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
StringCchCopyNW(szValue, ARRAYSIZE(Buffer), Buffer + MinLen, Length - MinLen);
|
|
|
|
SetUserEnvironmentVariable(Environment,
|
2015-06-26 18:59:25 +00:00
|
|
|
L"HOMEPATH",
|
|
|
|
szValue,
|
|
|
|
FALSE);
|
|
|
|
}
|
2004-03-19 12:40:49 +00:00
|
|
|
}
|
2015-08-08 09:50:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT1("GetUserProfileDirectoryW failed with error %lu\n", GetLastError());
|
|
|
|
}
|
2004-03-19 12:40:49 +00:00
|
|
|
|
2013-11-02 14:45:26 +00:00
|
|
|
if (GetUserAndDomainName(hToken,
|
|
|
|
&lpUserName,
|
|
|
|
&lpDomainName))
|
2007-07-28 16:29:33 +00:00
|
|
|
{
|
2016-12-08 16:12:59 +00:00
|
|
|
/* Set 'USERNAME' variable */
|
|
|
|
SetUserEnvironmentVariable(Environment,
|
|
|
|
L"USERNAME",
|
|
|
|
lpUserName,
|
|
|
|
FALSE);
|
|
|
|
|
2013-11-02 14:45:26 +00:00
|
|
|
/* Set 'USERDOMAIN' variable */
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironmentVariable(Environment,
|
2013-11-02 14:45:26 +00:00
|
|
|
L"USERDOMAIN",
|
|
|
|
lpDomainName,
|
|
|
|
FALSE);
|
|
|
|
|
2016-12-08 16:12:59 +00:00
|
|
|
if (lpUserName != NULL)
|
|
|
|
LocalFree(lpUserName);
|
|
|
|
|
|
|
|
if (lpDomainName != NULL)
|
|
|
|
LocalFree(lpDomainName);
|
2007-07-28 16:29:33 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
/* Set user environment variables */
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironment(Environment,
|
2010-05-05 22:53:01 +00:00
|
|
|
hKeyUser,
|
|
|
|
L"Environment");
|
2004-03-24 16:00:01 +00:00
|
|
|
|
2010-05-13 20:38:16 +00:00
|
|
|
/* Set user volatile environment variables */
|
2016-12-08 16:12:59 +00:00
|
|
|
SetUserEnvironment(Environment,
|
2010-05-13 20:38:16 +00:00
|
|
|
hKeyUser,
|
|
|
|
L"Volatile Environment");
|
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
RegCloseKey(hKeyUser);
|
2004-03-24 16:00:01 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
return TRUE;
|
2004-03-19 12:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2016-12-08 16:12:59 +00:00
|
|
|
DestroyEnvironmentBlock(IN LPVOID lpEnvironment)
|
2004-03-19 12:40:49 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
DPRINT("DestroyEnvironmentBlock() called\n");
|
2004-03-19 12:40:49 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
if (lpEnvironment == NULL)
|
2006-01-12 00:11:14 +00:00
|
|
|
{
|
2010-05-05 22:53:01 +00:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
2006-01-12 00:11:14 +00:00
|
|
|
}
|
2004-03-19 12:40:49 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
RtlDestroyEnvironment(lpEnvironment);
|
2004-03-19 12:40:49 +00:00
|
|
|
|
2010-05-05 22:53:01 +00:00
|
|
|
return TRUE;
|
2004-03-19 12:40:49 +00:00
|
|
|
}
|
|
|
|
|
2006-01-06 15:42:12 +00:00
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2006-01-06 15:42:12 +00:00
|
|
|
ExpandEnvironmentStringsForUserW(IN HANDLE hToken,
|
|
|
|
IN LPCWSTR lpSrc,
|
|
|
|
OUT LPWSTR lpDest,
|
|
|
|
IN DWORD dwSize)
|
|
|
|
{
|
|
|
|
BOOL Ret = FALSE;
|
2016-12-08 16:08:59 +00:00
|
|
|
PVOID lpEnvironment;
|
2006-01-06 15:42:12 +00:00
|
|
|
|
|
|
|
if (lpSrc == NULL || lpDest == NULL || dwSize == 0)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CreateEnvironmentBlock(&lpEnvironment,
|
|
|
|
hToken,
|
|
|
|
FALSE))
|
|
|
|
{
|
|
|
|
UNICODE_STRING SrcU, DestU;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
2016-12-08 16:08:59 +00:00
|
|
|
/* Initialize the strings */
|
|
|
|
RtlInitUnicodeString(&SrcU, lpSrc);
|
2006-01-06 15:42:12 +00:00
|
|
|
DestU.Length = 0;
|
|
|
|
DestU.MaximumLength = dwSize * sizeof(WCHAR);
|
|
|
|
DestU.Buffer = lpDest;
|
|
|
|
|
2016-12-08 16:08:59 +00:00
|
|
|
/* Expand the strings */
|
2006-01-06 15:42:12 +00:00
|
|
|
Status = RtlExpandEnvironmentStrings_U((PWSTR)lpEnvironment,
|
|
|
|
&SrcU,
|
|
|
|
&DestU,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
DestroyEnvironmentBlock(lpEnvironment);
|
|
|
|
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Ret = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-24 20:16:20 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2006-01-06 15:42:12 +00:00
|
|
|
ExpandEnvironmentStringsForUserA(IN HANDLE hToken,
|
|
|
|
IN LPCSTR lpSrc,
|
|
|
|
OUT LPSTR lpDest,
|
|
|
|
IN DWORD dwSize)
|
|
|
|
{
|
2016-12-08 16:08:59 +00:00
|
|
|
BOOL Ret = FALSE;
|
2006-01-06 15:42:12 +00:00
|
|
|
DWORD dwSrcLen;
|
|
|
|
LPWSTR lpSrcW = NULL, lpDestW = NULL;
|
|
|
|
|
|
|
|
if (lpSrc == NULL || lpDest == NULL || dwSize == 0)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwSrcLen = strlen(lpSrc);
|
|
|
|
lpSrcW = (LPWSTR)GlobalAlloc(GMEM_FIXED,
|
|
|
|
(dwSrcLen + 1) * sizeof(WCHAR));
|
|
|
|
if (lpSrcW == NULL ||
|
|
|
|
MultiByteToWideChar(CP_ACP,
|
|
|
|
0,
|
|
|
|
lpSrc,
|
|
|
|
-1,
|
|
|
|
lpSrcW,
|
|
|
|
dwSrcLen + 1) == 0)
|
|
|
|
{
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpDestW = (LPWSTR)GlobalAlloc(GMEM_FIXED,
|
|
|
|
dwSize * sizeof(WCHAR));
|
|
|
|
if (lpDestW == NULL)
|
|
|
|
goto Cleanup;
|
|
|
|
|
|
|
|
Ret = ExpandEnvironmentStringsForUserW(hToken,
|
|
|
|
lpSrcW,
|
|
|
|
lpDestW,
|
|
|
|
dwSize);
|
|
|
|
if (Ret)
|
|
|
|
{
|
|
|
|
if (WideCharToMultiByte(CP_ACP,
|
|
|
|
0,
|
|
|
|
lpDestW,
|
|
|
|
-1,
|
|
|
|
lpDest,
|
|
|
|
dwSize,
|
|
|
|
NULL,
|
|
|
|
NULL) == 0)
|
|
|
|
{
|
|
|
|
Ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
if (lpSrcW != NULL)
|
|
|
|
GlobalFree((HGLOBAL)lpSrcW);
|
|
|
|
|
|
|
|
if (lpDestW != NULL)
|
|
|
|
GlobalFree((HGLOBAL)lpDestW);
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2004-03-19 12:40:49 +00:00
|
|
|
/* EOF */
|