@@ -27,3 +27,35 @@ function Set-Display([int]$Width, [int]$Height) {
2727 $after = [System.Windows.Forms.Screen ]::PrimaryScreen.Bounds
2828 " before=$ ( $before.Width ) x$ ( $before.Height ) change=$code after=$ ( $after.Width ) x$ ( $after.Height ) "
2929}
30+
31+ Add-Type - Namespace Wg2 - Name Foreground - MemberDefinition @'
32+ [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
33+ [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint pid);
34+ '@
35+
36+ function Get-ForegroundProcess {
37+ [uint32 ]$owner = 0
38+ [Wg2.Foreground ]::GetWindowThreadProcessId([Wg2.Foreground ]::GetForegroundWindow(), [ref ]$owner ) | Out-Null
39+ $p = Get-Process - Id $owner - ErrorAction SilentlyContinue
40+ if ($p ) { " $ ( $p.ProcessName ) ($owner )" } else { " pid $owner " }
41+ }
42+
43+ # The Windows 11 Arm64 image signs in to "Choose privacy settings for your device", which covers the desktop and
44+ # keeps the foreground. The policy keeps it from coming back; the open page still has to be closed.
45+ function Clear-FirstLogon {
46+ $log = @ (" foreground before: $ ( Get-ForegroundProcess ) " )
47+ New-Item - Path ' HKLM:\SOFTWARE\Policies\Microsoft\Windows\OOBE' - Force | Out-Null
48+ Set-ItemProperty - Path ' HKLM:\SOFTWARE\Policies\Microsoft\Windows\OOBE' - Name ' DisablePrivacyExperience' - Value 1 - Type DWord
49+ $owner = (Get-ForegroundProcess ) -replace ' \(.*' , ' '
50+ $names = @ (' WWAHost' , ' CloudExperienceHostBroker' , ' UserOOBEBroker' )
51+ if ($owner -notin @ (' explorer' , ' pwsh' , ' powershell' , ' Runner.Worker' , ' pid 0' )) { $names += $owner }
52+ foreach ($name in $names | Select-Object - Unique) {
53+ foreach ($p in Get-Process - Name $name - ErrorAction SilentlyContinue) {
54+ $log += " stopping $ ( $p.ProcessName ) ($ ( $p.Id ) ) title='$ ( $p.MainWindowTitle ) '"
55+ Stop-Process - Id $p.Id - Force - ErrorAction SilentlyContinue
56+ }
57+ }
58+ Start-Sleep 3
59+ $log += " foreground after: $ ( Get-ForegroundProcess ) "
60+ $log -join ' ; '
61+ }
0 commit comments