[SYSSETUP] Add new Env section to unattend.inf

This allows to add environment variables during unattended setup
This commit is contained in:
Mark Jansen 2022-03-12 15:10:05 +01:00
parent 62d7486ef6
commit d4e38a630f
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B
2 changed files with 52 additions and 0 deletions

View file

@ -74,3 +74,8 @@ ProductOption = 0
; XResolution = 1440
; YResolution = 900
; VRefresh = 0
; enable this section to add environment variables
;[Env]
;WINETEST_PLATFORM=reactos

View file

@ -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