mirror of
https://github.com/reactos/reactos.git
synced 2025-07-03 01:21:23 +00:00
[KERNEL32] Store the current computer name in the volatile ActiveComputerName key on first query in order to ensure that the visible computer name does not change until the next reboot.
This commit is contained in:
parent
00dd17e6e5
commit
b2819c353c
1 changed files with 108 additions and 6 deletions
|
@ -122,6 +122,89 @@ failed:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
BOOL
|
||||||
|
SetActiveComputerNameToRegistry(LPCWSTR RegistryKey,
|
||||||
|
LPCWSTR SubKey,
|
||||||
|
LPCWSTR ValueNameStr,
|
||||||
|
LPCWSTR lpBuffer)
|
||||||
|
{
|
||||||
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
UNICODE_STRING KeyName;
|
||||||
|
UNICODE_STRING ValueName;
|
||||||
|
HANDLE KeyHandle, SubKeyHandle;
|
||||||
|
SIZE_T StringLength;
|
||||||
|
ULONG Disposition;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
StringLength = wcslen(lpBuffer);
|
||||||
|
if (StringLength > ((MAXULONG / sizeof(WCHAR)) - 1))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlInitUnicodeString(&KeyName, RegistryKey);
|
||||||
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
|
&KeyName,
|
||||||
|
OBJ_CASE_INSENSITIVE,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
Status = NtOpenKey(&KeyHandle,
|
||||||
|
KEY_WRITE,
|
||||||
|
&ObjectAttributes);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
BaseSetLastNTError(Status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlInitUnicodeString(&KeyName, SubKey);
|
||||||
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
|
&KeyName,
|
||||||
|
OBJ_CASE_INSENSITIVE,
|
||||||
|
KeyHandle,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
Status = NtCreateKey(&SubKeyHandle,
|
||||||
|
KEY_WRITE,
|
||||||
|
&ObjectAttributes,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
REG_OPTION_VOLATILE,
|
||||||
|
&Disposition);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
NtClose(KeyHandle);
|
||||||
|
BaseSetLastNTError(Status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlInitUnicodeString(&ValueName, ValueNameStr);
|
||||||
|
|
||||||
|
Status = NtSetValueKey(SubKeyHandle,
|
||||||
|
&ValueName,
|
||||||
|
0,
|
||||||
|
REG_SZ,
|
||||||
|
(PVOID)lpBuffer,
|
||||||
|
(StringLength + 1) * sizeof(WCHAR));
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
NtClose(SubKeyHandle);
|
||||||
|
NtClose(KeyHandle);
|
||||||
|
BaseSetLastNTError(Status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NtFlushKey(SubKeyHandle);
|
||||||
|
NtClose(SubKeyHandle);
|
||||||
|
NtClose(KeyHandle);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
|
@ -148,11 +231,28 @@ GetComputerNameExW(COMPUTER_NAME_FORMAT NameType,
|
||||||
switch (NameType)
|
switch (NameType)
|
||||||
{
|
{
|
||||||
case ComputerNameNetBIOS:
|
case ComputerNameNetBIOS:
|
||||||
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
ret = GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
L"\\Control\\ComputerName\\ComputerName",
|
L"\\Control\\ComputerName\\ActiveComputerName",
|
||||||
L"ComputerName",
|
L"ComputerName",
|
||||||
lpBuffer,
|
lpBuffer,
|
||||||
nSize);
|
nSize);
|
||||||
|
if (ret == FALSE)
|
||||||
|
{
|
||||||
|
ret = GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
|
L"\\Control\\ComputerName\\ComputerName",
|
||||||
|
L"ComputerName",
|
||||||
|
lpBuffer,
|
||||||
|
nSize);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
ret = SetActiveComputerNameToRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
|
L"\\Control\\ComputerName",
|
||||||
|
L"ActiveComputerName",
|
||||||
|
L"ComputerName",
|
||||||
|
lpBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
|
||||||
case ComputerNameDnsDomain:
|
case ComputerNameDnsDomain:
|
||||||
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
return GetComputerNameFromRegistry(L"\\Registry\\Machine\\System\\CurrentControlSet"
|
||||||
|
@ -323,7 +423,7 @@ GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
ret = GetComputerNameExA(ComputerNameNetBIOS, lpBuffer, lpnSize);
|
ret = GetComputerNameExA(ComputerNameNetBIOS, lpBuffer, lpnSize);
|
||||||
if (!ret && GetLastError() == ERROR_MORE_DATA)
|
if (!ret && GetLastError() == ERROR_MORE_DATA)
|
||||||
SetLastError(ERROR_BUFFER_OVERFLOW);
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
||||||
|
|
||||||
|
@ -339,9 +439,11 @@ WINAPI
|
||||||
GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
|
GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
ret=GetComputerNameExW(ComputerNameNetBIOS, lpBuffer, lpnSize);
|
|
||||||
if(!ret && GetLastError() == ERROR_MORE_DATA)
|
ret = GetComputerNameExW(ComputerNameNetBIOS, lpBuffer, lpnSize);
|
||||||
SetLastError(ERROR_BUFFER_OVERFLOW);
|
if (!ret && GetLastError() == ERROR_MORE_DATA)
|
||||||
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue