|
1 | | -# Exit early if this SID was already set up — prevents re-running after an accidental profile reset |
| 1 | +# Guard against re-running after a profile reset. Windows 24H2/25H2 can recreate a user profile |
| 2 | +# from the Default template after sleep/wake, which causes RunOnce to fire this script again. |
| 3 | +# We track per-SID completion in HKLM (survives profile resets, unlike HKCU) and exit early if |
| 4 | +# this user was already set up. -ErrorAction Stop ensures real errors are not silently swallowed. |
2 | 5 | $sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value |
3 | | -if ((Get-ItemProperty 'HKLM:\SOFTWARE\AtlasOS\UserSetup' -Name $sid -EA SilentlyContinue).$sid -eq 1) { exit } |
| 6 | +try { |
| 7 | + if ((Get-ItemProperty 'HKLM:\SOFTWARE\AtlasOS\UserSetup' -Name $sid -ErrorAction Stop).$sid -eq 1) { exit } |
| 8 | +} catch { |
| 9 | + # Key or property does not exist yet - this is the first run, continue normally |
| 10 | +} |
4 | 11 |
|
5 | 12 | $windir = [Environment]::GetFolderPath('Windows') |
6 | 13 | & "$windir\AtlasModules\initPowerShell.ps1" |
@@ -77,9 +84,17 @@ if ([string]::IsNullOrWhiteSpace($browser)) { |
77 | 84 | & "$atlasModules\Scripts\taskbarPins.ps1" $browser |
78 | 85 | & reg.exe add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v "SearchboxTaskbarMode" /t REG_DWORD /d 1 /f *> $null |
79 | 86 |
|
80 | | -# Mark this SID as set up so the guard above triggers on any future re-run |
81 | | -New-Item 'HKLM:\SOFTWARE\AtlasOS\UserSetup' -Force | Out-Null |
82 | | -Set-ItemProperty 'HKLM:\SOFTWARE\AtlasOS\UserSetup' -Name $sid -Value 1 -Type DWord -Force |
| 87 | +# Write the per-SID completion marker so the guard at the top of this script triggers on any |
| 88 | +# future re-run. The key is created if it does not exist yet. If writing fails for any reason |
| 89 | +# (e.g. permissions), a warning is shown so the failure is visible rather than silent. |
| 90 | +try { |
| 91 | + if (-not (Test-Path 'HKLM:\SOFTWARE\AtlasOS\UserSetup')) { |
| 92 | + New-Item 'HKLM:\SOFTWARE\AtlasOS\UserSetup' -Force | Out-Null |
| 93 | + } |
| 94 | + Set-ItemProperty 'HKLM:\SOFTWARE\AtlasOS\UserSetup' -Name $sid -Value 1 -Type DWord -Force |
| 95 | +} catch { |
| 96 | + Write-Warning "Failed to write setup marker for SID '$sid': $($_.Exception.Message)" |
| 97 | +} |
83 | 98 |
|
84 | 99 | # Leave |
85 | 100 | Start-Sleep 5 |
|
0 commit comments