Merge pull request 'fix(first-boot): online branding re-apply + deferred sm-bootstrap cleanup' (#13) from fix/branding-online-and-bootstrap-cleanup into main
Some checks failed
Build SilverMetal Enhanced - Windows ISO / build (push) Failing after 6m19s
Some checks failed
Build SilverMetal Enhanced - Windows ISO / build (push) Failing after 6m19s
Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
@@ -234,6 +234,11 @@ function Invoke-ServiceWim {
|
|||||||
Copy-Item (Join-Path $PSScriptRoot 'oem\SetupComplete.cmd') $scripts -Force
|
Copy-Item (Join-Path $PSScriptRoot 'oem\SetupComplete.cmd') $scripts -Force
|
||||||
Copy-Item (Join-Path $PSScriptRoot 'oem\Configure-Kiosk.ps1') $scripts -Force
|
Copy-Item (Join-Path $PSScriptRoot 'oem\Configure-Kiosk.ps1') $scripts -Force
|
||||||
Copy-Item (Join-Path $WindowsDir 'hardening\*') (Join-Path $scripts 'hardening') -Recurse -Force
|
Copy-Item (Join-Path $WindowsDir 'hardening\*') (Join-Path $scripts 'hardening') -Recurse -Force
|
||||||
|
# Stage the branding module so SetupComplete.cmd can re-apply branding ONLINE
|
||||||
|
# (Windows resets the offline personalization bake during OOBE).
|
||||||
|
$brandDest = Join-Path $scripts 'branding'
|
||||||
|
$null = New-Item -ItemType Directory -Force $brandDest
|
||||||
|
Copy-Item (Join-Path $WindowsDir 'branding\*') $brandDest -Recurse -Force
|
||||||
|
|
||||||
# Stage Welcome app + flavours while the WIM is still mounted.
|
# Stage Welcome app + flavours while the WIM is still mounted.
|
||||||
Copy-WelcomePayload
|
Copy-WelcomePayload
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ set HARD=C:\Windows\Setup\Scripts\hardening
|
|||||||
|
|
||||||
echo [%DATE% %TIME%] SilverMetal first-boot start >> "%LOG%"
|
echo [%DATE% %TIME%] SilverMetal first-boot start >> "%LOG%"
|
||||||
|
|
||||||
|
REM Re-apply branding ONLINE (lock screen / wallpaper / OEM / FVE). Windows resets
|
||||||
|
REM the offline-baked personalization during OOBE, so re-assert it here (post-OOBE,
|
||||||
|
REM as SYSTEM) where it sticks. Idempotent with the offline bake.
|
||||||
|
if exist "%~dp0branding\Apply-Branding.ps1" (
|
||||||
|
echo [%DATE% %TIME%] re-applying SilverMetal branding (online) >> "%LOG%"
|
||||||
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0branding\Apply-Branding.ps1" -Mode Online >> "%LOG%" 2>&1
|
||||||
|
)
|
||||||
|
|
||||||
if exist "C:\Program Files\SilverOS\Welcome\SilverOS.Welcome.App.exe" (
|
if exist "C:\Program Files\SilverOS\Welcome\SilverOS.Welcome.App.exe" (
|
||||||
echo [%DATE% %TIME%] configuring onboarding kiosk >> "%LOG%"
|
echo [%DATE% %TIME%] configuring onboarding kiosk >> "%LOG%"
|
||||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0Configure-Kiosk.ps1" >> "%LOG%" 2>&1
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0Configure-Kiosk.ps1" >> "%LOG%" 2>&1
|
||||||
|
|||||||
@@ -36,7 +36,19 @@ public sealed class BootstrapService(IProcessRunner runner) : IBootstrapService
|
|||||||
$"Remove-ItemProperty -Path {w} -Name DefaultUserName -EA SilentlyContinue; " +
|
$"Remove-ItemProperty -Path {w} -Name DefaultUserName -EA SilentlyContinue; " +
|
||||||
$"Remove-ItemProperty -Path {w} -Name DefaultDomainName -EA SilentlyContinue", ct);
|
$"Remove-ItemProperty -Path {w} -Name DefaultDomainName -EA SilentlyContinue", ct);
|
||||||
var u = Esc(bootstrapUser);
|
var u = Esc(bootstrapUser);
|
||||||
|
// Best-effort in-session removal (usually no-ops — you can't delete the account
|
||||||
|
// you're logged in as), THEN defer the real removal to a SYSTEM startup task that
|
||||||
|
// runs on next boot, when sm-bootstrap is no longer logged on. It removes the
|
||||||
|
// account + profile, then deletes itself. Encoded command avoids schtasks quoting.
|
||||||
await Ps($"Remove-LocalUser -Name '{u}' -EA SilentlyContinue", ct);
|
await Ps($"Remove-LocalUser -Name '{u}' -EA SilentlyContinue", ct);
|
||||||
|
var cleanup =
|
||||||
|
$"Remove-LocalUser -Name '{u}' -ErrorAction SilentlyContinue; " +
|
||||||
|
$"Get-CimInstance Win32_UserProfile | Where-Object {{ $_.LocalPath -like '*\\{u}' }} | Remove-CimInstance -ErrorAction SilentlyContinue; " +
|
||||||
|
"schtasks /delete /tn 'SilverMetalBootstrapCleanup' /f";
|
||||||
|
var b64 = Convert.ToBase64String(System.Text.Encoding.Unicode.GetBytes(cleanup));
|
||||||
|
await Ps("schtasks /create /tn 'SilverMetalBootstrapCleanup' " +
|
||||||
|
$"/tr 'powershell -NoProfile -ExecutionPolicy Bypass -EncodedCommand {b64}' " +
|
||||||
|
"/sc onstart /ru SYSTEM /rl HIGHEST /f", ct);
|
||||||
}
|
}
|
||||||
private static string Esc(string s) => s.Replace("'", "''");
|
private static string Esc(string s) => s.Replace("'", "''");
|
||||||
private Task Ps(string s, CancellationToken ct) =>
|
private Task Ps(string s, CancellationToken ct) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user