-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: resolve Apply to All Users for tweaks #3602 #3630
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
base: main
Are you sure you want to change the base?
fix: resolve Apply to All Users for tweaks #3602 #3630
Conversation
Add checkbox UI to apply registry tweaks to all user profiles (HKEY_USERS) when enabled. Implements per-user hive iteration in Invoke-WinUtilTweaks with safety filters for system SIDs. Updates all tweak handlers to pass the new ApplyToAllUsers parameter. Fixes ChrisTitusTech#3602
| # If the path targets HKCU and user requested ApplyToAllUsers, iterate through HKEY_USERS and apply to each user's hive | ||
| if ($ApplyToAllUsers -and ($psitem.Path -imatch "HKCU:" -or $psitem.Path -imatch "HKEY_CURRENT_USER")) { | ||
| try { | ||
| if(!(Test-Path 'HKU:\')) {New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS} | ||
| $users = Get-ChildItem -Path HKU:\ | Where-Object { $_.PSChildName -notin @('S-1-5-18','S-1-5-19','S-1-5-20','.DEFAULT') } | ||
| foreach ($user in $users) { | ||
| $userHive = $user.PSPath -replace '^Registry::','' | ||
| # Build a HKU path equivalent to the HKCU path | ||
| $relative = $psitem.Path -replace '^(HKCU:|HKEY_CURRENT_USER\\?)','' | ||
| $targetPath = "HKU:\$($user.PSChildName)\$relative" | ||
| try { | ||
| if (!(Test-Path $targetPath)) { | ||
| New-Item -Path $targetPath -Force | Out-Null | ||
| } | ||
| Set-WinUtilRegistry -Name $psitem.Name -Path $targetPath -Type $psitem.Type -Value $psitem.$($values.registry) | ||
| } catch { | ||
| Write-Warning "Failed to set $targetPath\$($psitem.Name): $_" | ||
| } | ||
| } | ||
| } catch { | ||
| Write-Warning "Failed enumerating user hives: $_" | ||
| } | ||
| } | ||
| else { | ||
| if (($psitem.Path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) { | ||
| $null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS) | ||
| if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) { | ||
| Write-Debug "HKU drive created successfully" | ||
| } else { | ||
| Write-Debug "Failed to create HKU drive" | ||
| } |
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.
Oh my god...
|
This was a godsend, since after installing windows 11, I wanted to have multiple accounts on the machine, to separate the levels of permissions. I was able to finally apply most of the tweaks to all the hives individually with this, which is great. One of the accounts is logged in with a Microsoft account, but I wish to disable one drive globally. This does not appear to work for me (which could be my own doing). The vanilla util applies it only to the main admin account even when ran from a different account using admin privileges. Using this branch the OneDrive tweak just exits immediately, so that code may need additional modifications to work on a multi-user workstation IE iterating through hives to make reg edits AND iterating through multiple users to move the files. |
ChrisTitusTech
left a comment
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.
Clean up the if/else try/catch nesting. Its messy and it doesn't need to be that long.
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.
This looks like it will not handle unloaded registry hives, leaving profiles for accounts that are not currently logged on without the tweaks.
I would recommend these changes:
:: Ensure HKU drive exists if needed
if ($ApplyToAllUsers -and $psitem.Path -match "^(HKCU:|HKEY_CURRENT_USER)") {
if (!(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS | Out-Null
}
$relativePath = $psitem.Path -replace '^(HKCU:|HKEY_CURRENT_USER\\?)', ''
$excludedSIDs = @('S-1-5-18', 'S-1-5-19', 'S-1-5-20', '.DEFAULT')
Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\*" -ErrorAction SilentlyContinue |
Where-Object { $_.PSChildName -notin $excludedSIDs -and $_.ProfileImagePath } |
ForEach-Object {
$sid = $_.PSChildName
$ntUserPath = Join-Path $_.ProfileImagePath "NTUSER.DAT"
$needsUnload = !(Test-Path "HKU:\$sid")
if ($needsUnload -and (Test-Path $ntUserPath)) {
reg load "HKU\$sid" "$ntUserPath" 2>&1 | Out-Null
Start-Sleep -Milliseconds 100
}
try {
$targetPath = "HKU:\$sid\$relativePath"
if (!(Test-Path $targetPath)) { New-Item -Path $targetPath -Force | Out-Null }
Set-WinUtilRegistry -Name $psitem.Name -Path $targetPath -Type $psitem.Type -Value $psitem.$($values.registry)
} catch {
Write-Warning "Failed to set registry for SID $sid : $_"
}
if ($needsUnload) {
[System.GC]::Collect()
reg unload "HKU\$sid" 2>&1 | Out-Null
}
}
}
or I'm delulu and need more coffee... could be that one.
This commit addresses review feedback regarding the 'Apply to All Users' functionality and code structure in Invoke-WinUtilTweaks.ps1. Changes: - Refactored nested if/else logic to reduce complexity and improve readability. - Updated registry tweak logic to correctly handle offline user profiles when 'Apply to All Users' is selected. - Implemented `reg load` and `reg unload` for `NTUSER.DAT`, ensuring tweaks are applied even if the user is not currently logged in. - Added safety checks to ensure the HKU drive is mounted before attempting operations.
Type of Change
Description
This PR resolves issue #3602 by implementing an "Apply to All Users" feature for registry tweaks in the winutil tool.
What was changed:
How it works:
Files modified:
xaml/inputXML.xaml(+6/-0) - Added checkbox UIfunctions/public/Invoke-WPFtweaksbutton.ps1(+10/-3) - Read checkbox state and pass to runspacefunctions/private/Invoke-WinUtilTweaks.ps1(+28/-1) - Core per-user iteration logicfunctions/public/Invoke-WPFUIElements.ps1(+6/-2) - Updated per-toggle handlersfunctions/public/Invoke-WPFundoall.ps1(+7/-3) - Updated undo operationsTesting
Manual testing performed:
Testing recommendations for reviewers:
Impact
Positive impacts:
Performance considerations:
New dependencies:
Behavioral changes:
Issue related to PR
Additional Information
Edge cases and notes:
Future enhancements (not included in this PR):
Checklist