From 2bf6ae55abf66267b2367034dbe44e70ddbb0abc Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 18 Aug 2026 02:15:37 +0200 Subject: [PATCH] feat: Hide first-logon console during answer generation (#2152) --- src/answer.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/answer.sh b/src/answer.sh index 58559eed..65c46978 100644 --- a/src/answer.sh +++ b/src/answer.sh @@ -71,6 +71,11 @@ updateXML() { return 1 fi + if ! updateLogonCommandXML "$asset"; then + error "Failed to update first-logon command in answer file!" + return 1 + fi + if ! updateEditionXML "$asset"; then error "Failed to update edition settings in answer file!" return 1 @@ -521,6 +526,38 @@ updateAutologinXML() { return 0 } +updateLogonCommandXML() { + + local asset="$1" + + case "${DETECTED,,}" in + "winvista"* ) return 0 ;; + esac + + local command="$XML_COMPONENT_SHELL_OOBE/u:FirstLogonCommands/u:SynchronousCommand/u:CommandLine" + local expected='cmd.exe /d /c call "%WINDIR%\Setup\Scripts\SetupComplete.cmd" logon' + local hidden="powershell.exe -NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -Command \"& \$env:ComSpec /d /c ('call ' + [char]34 + \$env:WINDIR + '\Setup\Scripts\SetupComplete.cmd' + [char]34 + ' logon'); exit \$LASTEXITCODE\"" + + local count value + count=$(getXMLNodeCount "$asset" "$command") || return 1 + + if [ "$count" != "1" ]; then + error "Failed to find a unique first-logon command in answer file: $asset" + return 1 + fi + + value=$(xmlstarlet sel -N "$XML_NS_UNATTEND_ARG" -T -t -v "string($command)" "$asset") || return 1 + + if [ "$value" != "$expected" ]; then + error "Unexpected first-logon command in answer file: $asset" + return 1 + fi + + xmlstarlet ed -L -N "$XML_NS_UNATTEND_ARG" -u "$command" -v "$hidden" "$asset" || return 1 + + return 0 +} + updateProductKey() { local script="$1"