From d4e38a630ff8e7ad6ec5409a9b25be3ae596e9dd Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Sat, 12 Mar 2022 15:10:05 +0100 Subject: [PATCH] [SYSSETUP] Add new Env section to unattend.inf This allows to add environment variables during unattended setup --- boot/bootdata/bootcd/unattend.inf | 5 ++++ dll/win32/syssetup/wizard.c | 47 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/boot/bootdata/bootcd/unattend.inf b/boot/bootdata/bootcd/unattend.inf index ce5593788e2..dcf98b732f4 100644 --- a/boot/bootdata/bootcd/unattend.inf +++ b/boot/bootdata/bootcd/unattend.inf @@ -74,3 +74,8 @@ ProductOption = 0 ; XResolution = 1440 ; YResolution = 900 ; VRefresh = 0 + +; enable this section to add environment variables +;[Env] +;WINETEST_PLATFORM=reactos + diff --git a/dll/win32/syssetup/wizard.c b/dll/win32/syssetup/wizard.c index 233b87aa184..75842349d3e 100644 --- a/dll/win32/syssetup/wizard.c +++ b/dll/win32/syssetup/wizard.c @@ -2831,6 +2831,53 @@ ProcessUnattendSection( } RegCloseKey(hKey); + + if (SetupFindFirstLineW(pSetupData->hSetupInf, + L"Env", + NULL, + &InfContext)) + { + if (RegCreateKeyExW( + HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", 0, NULL, + REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &hKey, NULL) != ERROR_SUCCESS) + { + DPRINT1("Error: failed to open HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\n"); + return; + } + do + { + if (!SetupGetStringFieldW(&InfContext, + 0, + szName, + ARRAYSIZE(szName), + &LineLength)) + { + DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError()); + return; + } + + if (!SetupGetStringFieldW(&InfContext, + 1, + szValue, + ARRAYSIZE(szValue), + &LineLength)) + { + DPRINT1("Error: SetupGetStringField failed with %d\n", GetLastError()); + return; + } + DPRINT1("[ENV] %S=%S\n", szName, szValue); + + DWORD dwType = wcschr(szValue, '%') != NULL ? REG_EXPAND_SZ : REG_SZ; + + if (RegSetValueExW(hKey, szName, 0, dwType, (const BYTE*)szValue, (DWORD)(wcslen(szValue) + 1) * sizeof(TCHAR)) != ERROR_SUCCESS) + { + DPRINT1(" - Error %d\n", GetLastError()); + } + + } while (SetupFindNextLine(&InfContext, &InfContext)); + + RegCloseKey(hKey); + } } VOID