-
Notifications
You must be signed in to change notification settings - Fork 0
Guard newUsers.ps1 against re-running on accidental Windows profile reset #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,9 @@ | ||||||||||||||||||||
| if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | ||||||||||||||||||||
| Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit | ||||||||||||||||||||
| # Guard against re-running on already-configured accounts (e.g., after profile reset) | ||||||||||||||||||||
| $sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value | ||||||||||||||||||||
| if ((Get-ItemProperty -Path "HKLM:\SOFTWARE\AtlasOS\UserSetup" -Name $sid -ErrorAction SilentlyContinue).$sid -eq 1) { exit } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | ||||||||||||||||||||
| Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| $windir = [Environment]::GetFolderPath('Windows') | ||||||||||||||||||||
|
|
@@ -51,6 +55,10 @@ $Browser | |||||||||||||||||||
| & "$atlasModules\Scripts\taskbarPins.ps1" $Browser | ||||||||||||||||||||
| Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" -Name "SearchboxTaskbarMode" -Value 1 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Mark setup complete for this SID to prevent re-runs after profile reset | ||||||||||||||||||||
| New-Item -Path "HKLM:\SOFTWARE\AtlasOS\UserSetup" -Force | Out-Null | ||||||||||||||||||||
| New-ItemProperty -Path "HKLM:\SOFTWARE\AtlasOS\UserSetup" -Name $sid -Value 1 -PropertyType DWord -Force | Out-Null | ||||||||||||||||||||
|
Comment on lines
+59
to
+60
|
||||||||||||||||||||
| New-Item -Path "HKLM:\SOFTWARE\AtlasOS\UserSetup" -Force | Out-Null | |
| New-ItemProperty -Path "HKLM:\SOFTWARE\AtlasOS\UserSetup" -Name $sid -Value 1 -PropertyType DWord -Force | Out-Null | |
| try { | |
| New-Item -Path "HKLM:\SOFTWARE\AtlasOS\UserSetup" -Force -ErrorAction Stop | Out-Null | |
| New-ItemProperty -Path "HKLM:\SOFTWARE\AtlasOS\UserSetup" -Name $sid -Value 1 -PropertyType DWord -Force -ErrorAction Stop | Out-Null | |
| } catch { | |
| Write-Error "Failed to mark user setup completion in HKLM:\SOFTWARE\AtlasOS\UserSetup for SID '$sid'. Aborting logoff. $_" | |
| exit 1 | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The re-run guard uses Get-ItemProperty and then dynamic member access (…).$sid, which is a bit brittle/opaque for a registry value name containing dashes. Consider using Get-ItemPropertyValue (or explicitly reading the property via .PSObject.Properties) so the intent is clearer and you avoid edge cases around property name handling.