Update src/samy.functions.ps1
This commit is contained in:
@@ -85,6 +85,103 @@ function Initialize-NuGetProvider {
|
||||
}
|
||||
}
|
||||
|
||||
#region re-usable unction
|
||||
function Set-RegistryValueForCurrentAndAllUsers {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)] [string] $RelativeKeyPath, # e.g. "Software\...\Explorer\Advanced"
|
||||
[Parameter(Mandatory)] [string] $Name,
|
||||
[Parameter(Mandatory)] [ValidateSet('String','ExpandString','DWord','QWord','Binary','MultiString')] [string] $Type,
|
||||
[Parameter(Mandatory)] $Value
|
||||
)
|
||||
|
||||
# Helper: write to a specific HKU root (SID or temp mount)
|
||||
function _SetValueInHkuRoot {
|
||||
param([Parameter(Mandatory)] [string] $HkuRoot) # e.g. "Registry::HKEY_USERS\S-1-5-21-..."
|
||||
$k = Join-Path $HkuRoot $RelativeKeyPath
|
||||
|
||||
if (-not (Test-Path $k)) { New-Item -Path $k -Force | Out-Null }
|
||||
|
||||
if ($Type -in @('String','ExpandString','MultiString','Binary')) {
|
||||
New-ItemProperty -Path $k -Name $Name -PropertyType $Type -Value $Value -Force | Out-Null
|
||||
} elseif ($Type -in @('DWord','QWord')) {
|
||||
New-ItemProperty -Path $k -Name $Name -PropertyType $Type -Value ([int64]$Value) -Force | Out-Null
|
||||
} else {
|
||||
# Fallback
|
||||
New-ItemProperty -Path $k -Name $Name -PropertyType $Type -Value $Value -Force | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
# 1) Current user (HKCU) - if meaningful in this context
|
||||
try {
|
||||
$hkcuKey = "HKCU:\$RelativeKeyPath"
|
||||
if (-not (Test-Path $hkcuKey)) { New-Item -Path $hkcuKey -Force | Out-Null }
|
||||
|
||||
New-ItemProperty -Path $hkcuKey -Name $Name -PropertyType $Type -Value $Value -Force | Out-Null
|
||||
} catch {
|
||||
# Common during SYSTEM runs; ignore
|
||||
}
|
||||
|
||||
# 2) Default User (future users)
|
||||
$defaultDat = "C:\Users\Default\NTUSER.DAT"
|
||||
if (Test-Path $defaultDat) {
|
||||
$mount = "HKU\SVS_DefaultUser"
|
||||
& reg.exe load $mount $defaultDat 2>$null | Out-Null
|
||||
|
||||
try {
|
||||
_SetValueInHkuRoot -HkuRoot "Registry::HKEY_USERS\SVS_DefaultUser"
|
||||
} finally {
|
||||
& reg.exe unload $mount 2>$null | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
# 3) All existing user profiles
|
||||
$profileList = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
|
||||
Get-ChildItem $profileList -ErrorAction SilentlyContinue | ForEach-Object {
|
||||
$sid = $_.PSChildName
|
||||
if ($sid -notmatch '^S-1-5-21-\d+-\d+-\d+-\d+$') { return }
|
||||
|
||||
# If hive is already loaded (user logged in), write directly to HKU:\SID
|
||||
$loaded = Test-Path "Registry::HKEY_USERS\$sid"
|
||||
|
||||
if ($loaded) {
|
||||
try { _SetValueInHkuRoot -HkuRoot "Registry::HKEY_USERS\$sid" } catch {}
|
||||
return
|
||||
}
|
||||
|
||||
# Otherwise load NTUSER.DAT from profile path
|
||||
$profilePath = (Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue).ProfileImagePath
|
||||
if (-not $profilePath) { return }
|
||||
|
||||
$ntuser = Join-Path $profilePath "NTUSER.DAT"
|
||||
if (-not (Test-Path $ntuser)) { return }
|
||||
|
||||
$tempMount = "HKU\SVS_$sid"
|
||||
& reg.exe load $tempMount $ntuser 2>$null | Out-Null
|
||||
|
||||
try {
|
||||
_SetValueInHkuRoot -HkuRoot "Registry::HKEY_USERS\SVS_$sid"
|
||||
} finally {
|
||||
& reg.exe unload $tempMount 2>$null | Out-Null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Restart-ExplorerIfInteractive {
|
||||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
# Don’t kill Explorer during SYSTEM/unboxing contexts where it may not exist or may be harmful
|
||||
$isSystem = ($env:USERNAME -eq 'SYSTEM')
|
||||
|
||||
if (-not $isSystem) {
|
||||
Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue
|
||||
Start-Process explorer.exe
|
||||
}
|
||||
}
|
||||
|
||||
#rendegion re-usable function
|
||||
|
||||
#region App handlers
|
||||
|
||||
function Invoke-Install1Password {
|
||||
@@ -150,39 +247,33 @@ function Initialize-NuGetProvider {
|
||||
}
|
||||
}
|
||||
|
||||
# If user checked the master box but no suboptions were chosen, pick a sensible default
|
||||
if ($selected.Count -eq 0) {
|
||||
$selected = @('window','taskbar','menus')
|
||||
}
|
||||
|
||||
# --- Window animations (min/max) ---
|
||||
if ($selected -contains 'window') {
|
||||
$k = "HKCU:\Control Panel\Desktop\WindowMetrics"
|
||||
New-Item -Path $k -Force | Out-Null
|
||||
Set-ItemProperty -Path $k -Name "MinAnimate" -Value "0" -Type String
|
||||
Set-RegistryValueForCurrentAndAllUsers `
|
||||
-RelativeKeyPath "Control Panel\Desktop\WindowMetrics" `
|
||||
-Name "MinAnimate" -Type String -Value "0"
|
||||
}
|
||||
|
||||
# --- Taskbar animations ---
|
||||
if ($selected -contains 'taskbar') {
|
||||
$k = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
|
||||
New-Item -Path $k -Force | Out-Null
|
||||
New-ItemProperty -Path $k -Name "TaskbarAnimations" -PropertyType DWord -Value 0 -Force | Out-Null
|
||||
Set-RegistryValueForCurrentAndAllUsers `
|
||||
-RelativeKeyPath "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" `
|
||||
-Name "TaskbarAnimations" -Type DWord -Value 0
|
||||
}
|
||||
|
||||
# --- Menus feel instant (lower delay) ---
|
||||
if ($selected -contains 'menus') {
|
||||
$k = "HKCU:\Control Panel\Desktop"
|
||||
New-Item -Path $k -Force | Out-Null
|
||||
Set-ItemProperty -Path $k -Name "MenuShowDelay" -Value "50" -Type String
|
||||
Set-RegistryValueForCurrentAndAllUsers `
|
||||
-RelativeKeyPath "Control Panel\Desktop" `
|
||||
-Name "MenuShowDelay" -Type String -Value "50"
|
||||
}
|
||||
|
||||
# Explorer restart helps taskbar changes apply faster
|
||||
if ($selected -contains 'taskbar') {
|
||||
Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue
|
||||
Start-Process explorer.exe
|
||||
Restart-ExplorerIfInteractive
|
||||
}
|
||||
|
||||
Write-LogHybrid "Disable Animations applied. Selected: $($selected -join ', ')" Success Tweaks -LogToEvent
|
||||
Write-LogHybrid "Disable Animations applied (Current + All Existing + Default User). Selected: $($selected -join ', ')" Success Tweaks -LogToEvent
|
||||
Send-Text $Context "Disable Animations applied: $($selected -join ', ')"
|
||||
}
|
||||
catch {
|
||||
@@ -191,6 +282,7 @@ function Initialize-NuGetProvider {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Invoke-EnableNumLock {
|
||||
param($Context)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user