From 88637f32f544fbc26bb58162815cf07dac0109ef Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 23 May 2010 19:27:04 +0000 Subject: [PATCH] [SMSS] - Remove the system environment variable OS from the hivesys*.inf files. - Change the type of the system environment variable PATHEXT in the hivesys*.inf files from REG_EXPAND_SZ to REG_SZ. - Let SMSS add the system environment variables OS and NUMBER_OF_PROCESSORS to the registry. svn path=/trunk/; revision=47333 --- reactos/base/system/smss/initenv.c | 117 +++++++++++++++++++++---- reactos/boot/bootdata/hivesys_arm.inf | 3 +- reactos/boot/bootdata/hivesys_i386.inf | 3 +- 3 files changed, 100 insertions(+), 23 deletions(-) diff --git a/reactos/base/system/smss/initenv.c b/reactos/base/system/smss/initenv.c index e97cf28c6aa..6580b4b6716 100644 --- a/reactos/base/system/smss/initenv.c +++ b/reactos/base/system/smss/initenv.c @@ -65,33 +65,116 @@ SmpEnvironmentQueryRoutine(IN PWSTR ValueName, NTSTATUS SmSetEnvironmentVariables(VOID) { - PWSTR ProcessorArchitecture = L""; + SYSTEM_BASIC_INFORMATION BasicInformation; + RTL_QUERY_REGISTRY_TABLE QueryTable[3]; UNICODE_STRING Identifier; UNICODE_STRING VendorIdentifier; - UNICODE_STRING ProcessorIdentifier; WCHAR Buffer[256]; + + UNICODE_STRING EnvironmentKeyName; + OBJECT_ATTRIBUTES ObjectAttributes; + HANDLE EnvironmentKey; + UNICODE_STRING VariableName; + PWSTR VariableData; + NTSTATUS Status; + + Status = NtQuerySystemInformation(SystemBasicInformation, + &BasicInformation, + sizeof(SYSTEM_BASIC_INFORMATION), + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SM: Failed to retrieve system basic information (Status %08lx)", Status); + return Status; + } + + RtlInitUnicodeString(&EnvironmentKeyName, + L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Session Manager\\Environment"); + InitializeObjectAttributes(&ObjectAttributes, + &EnvironmentKeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + /* Open the system environment key */ + Status = NtOpenKey(&EnvironmentKey, + GENERIC_WRITE, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SM: Failed to open the environment key (Status %08lx)", Status); + return Status; + } + + /* Set the 'NUMBER_OF_PROCESSORS' system environment variable */ + RtlInitUnicodeString(&VariableName, + L"NUMBER_OF_PROCESSORS"); + + swprintf(Buffer, L"%lu", BasicInformation.NumberOfProcessors); + + Status = NtSetValueKey(EnvironmentKey, + &VariableName, + 0, + REG_SZ, + Buffer, + (wcslen(Buffer) + 1) * sizeof(WCHAR)); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SM: Failed to set the NUMBER_OF_PROCESSORS environment variable (Status %08lx)", Status); + goto done; + } + + /* Set the 'OS' system environment variable */ + RtlInitUnicodeString(&VariableName, + L"OS"); + + VariableData = L"ReactOS"; + + Status = NtSetValueKey(EnvironmentKey, + &VariableName, + 0, + REG_SZ, + VariableData, + (wcslen(VariableData) + 1) * sizeof(WCHAR)); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SM: Failed to set the OS environment variable (Status %08lx)", Status); + goto done; + } + /* Set the 'PROCESSOR_ARCHITECTURE' system environment variable */ + RtlInitUnicodeString(&VariableName, + L"PROCESSOR_ARCHITECTURE"); + #ifdef _M_IX86 - ProcessorArchitecture = L"x86"; + VariableData = L"x86"; #elif _M_MD64 - ProcessorArchitecture = L"AMD64"; + VariableData = L"AMD64"; #elif _M_ARM - ProcessorArchitecture = L"ARM"; + VariableData = L"ARM"; #elif _M_PPC - ProcessorArchitecture = L"PPC"; + VariableData = L"PPC"; #else #error "Unsupported Architecture!\n" #endif - RtlWriteRegistryValue(RTL_REGISTRY_CONTROL, - L"Session Manager\\Environment", - L"PROCESSOR_ARCHITECTURE", - REG_SZ, - ProcessorArchitecture, - (wcslen(ProcessorArchitecture) + 1) * sizeof(WCHAR)); + Status = NtSetValueKey(EnvironmentKey, + &VariableName, + 0, + REG_SZ, + VariableData, + (wcslen(VariableData) + 1) * sizeof(WCHAR)); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SM: Failed to set the PROCESSOR_ARCHITECTURE environment variable (Status %08lx)", Status); + goto done; + } + +done: + NtClose(EnvironmentKey); /* Set the 'PROCESSOR_IDENTIFIER' system environment variable */ @@ -119,18 +202,14 @@ SmSetEnvironmentVariables(VOID) DPRINT("SM: szIdentifier: %wZ\n", &Identifier); DPRINT("SM: szVendorIdentifier: %wZ\n", &VendorIdentifier); - RtlInitEmptyUnicodeString(&ProcessorIdentifier, Buffer, 256 * sizeof(WCHAR)); - - RtlAppendUnicodeStringToString(&ProcessorIdentifier, &Identifier); - RtlAppendUnicodeToString(&ProcessorIdentifier, L", "); - RtlAppendUnicodeStringToString(&ProcessorIdentifier, &VendorIdentifier); + swprintf(Buffer, L"%wZ, %wZ", &Identifier, &VendorIdentifier); RtlWriteRegistryValue(RTL_REGISTRY_CONTROL, L"Session Manager\\Environment", L"PROCESSOR_IDENTIFIER", REG_SZ, - ProcessorIdentifier.Buffer, - (wcslen(ProcessorIdentifier.Buffer) + 1) * sizeof(WCHAR)); + Buffer, + (wcslen(Buffer) + 1) * sizeof(WCHAR)); } RtlFreeUnicodeString(&Identifier); diff --git a/reactos/boot/bootdata/hivesys_arm.inf b/reactos/boot/bootdata/hivesys_arm.inf index 39e94e157a7..dbe7d1b210c 100644 --- a/reactos/boot/bootdata/hivesys_arm.inf +++ b/reactos/boot/bootdata/hivesys_arm.inf @@ -754,12 +754,11 @@ HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices","UNC",0x0000 ; System environment settings HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","ComSpec",0x00020000,"%SystemRoot%\system32\cmd.exe" -HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","OS",0x00020000,"ReactOS" HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","Path",0x00020000,"%SystemRoot%\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\wbem" HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","windir",0x00020000,"%SystemRoot%" HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","TEMP",0x00020000,"%SystemDrive%\TEMP" HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","TMP",0x00020000,"%SystemDrive%\TEMP" -HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATHEXT",0x00020000,".COM;.EXE;.BAT;.CMD" +HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATHEXT",0x00000000,".COM;.EXE;.BAT;.CMD" ; Known DLLs diff --git a/reactos/boot/bootdata/hivesys_i386.inf b/reactos/boot/bootdata/hivesys_i386.inf index e46e6b3257d..db355022871 100644 --- a/reactos/boot/bootdata/hivesys_i386.inf +++ b/reactos/boot/bootdata/hivesys_i386.inf @@ -901,12 +901,11 @@ HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices","UNC",0x0000 ; System environment settings HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","ComSpec",0x00020000,"%SystemRoot%\system32\cmd.exe" -HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","OS",0x00020000,"ReactOS" HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","Path",0x00020000,"%SystemRoot%\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\wbem" HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","windir",0x00020000,"%SystemRoot%" HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","TEMP",0x00020000,"%SystemDrive%\TEMP" HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","TMP",0x00020000,"%SystemDrive%\TEMP" -HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATHEXT",0x00020000,".COM;.EXE;.BAT;.CMD" +HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATHEXT",0x00000000,".COM;.EXE;.BAT;.CMD" ; Known DLLs