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
|
#region App handlers
|
||||||
|
|
||||||
function Invoke-Install1Password {
|
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) {
|
if ($selected.Count -eq 0) {
|
||||||
$selected = @('window','taskbar','menus')
|
$selected = @('window','taskbar','menus')
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Window animations (min/max) ---
|
|
||||||
if ($selected -contains 'window') {
|
if ($selected -contains 'window') {
|
||||||
$k = "HKCU:\Control Panel\Desktop\WindowMetrics"
|
Set-RegistryValueForCurrentAndAllUsers `
|
||||||
New-Item -Path $k -Force | Out-Null
|
-RelativeKeyPath "Control Panel\Desktop\WindowMetrics" `
|
||||||
Set-ItemProperty -Path $k -Name "MinAnimate" -Value "0" -Type String
|
-Name "MinAnimate" -Type String -Value "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Taskbar animations ---
|
|
||||||
if ($selected -contains 'taskbar') {
|
if ($selected -contains 'taskbar') {
|
||||||
$k = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
|
Set-RegistryValueForCurrentAndAllUsers `
|
||||||
New-Item -Path $k -Force | Out-Null
|
-RelativeKeyPath "Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" `
|
||||||
New-ItemProperty -Path $k -Name "TaskbarAnimations" -PropertyType DWord -Value 0 -Force | Out-Null
|
-Name "TaskbarAnimations" -Type DWord -Value 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Menus feel instant (lower delay) ---
|
|
||||||
if ($selected -contains 'menus') {
|
if ($selected -contains 'menus') {
|
||||||
$k = "HKCU:\Control Panel\Desktop"
|
Set-RegistryValueForCurrentAndAllUsers `
|
||||||
New-Item -Path $k -Force | Out-Null
|
-RelativeKeyPath "Control Panel\Desktop" `
|
||||||
Set-ItemProperty -Path $k -Name "MenuShowDelay" -Value "50" -Type String
|
-Name "MenuShowDelay" -Type String -Value "50"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Explorer restart helps taskbar changes apply faster
|
|
||||||
if ($selected -contains 'taskbar') {
|
if ($selected -contains 'taskbar') {
|
||||||
Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue
|
Restart-ExplorerIfInteractive
|
||||||
Start-Process explorer.exe
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ', ')"
|
Send-Text $Context "Disable Animations applied: $($selected -join ', ')"
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
@@ -191,6 +282,7 @@ function Initialize-NuGetProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function Invoke-EnableNumLock {
|
function Invoke-EnableNumLock {
|
||||||
param($Context)
|
param($Context)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user