mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-11-26 07:26:18 +01:00
remove: disable Drag Tray feature and related configurations (#850)
To ensure old backups continue to function, backup handling now skips any unknown features found in backups.
This commit is contained in:
@@ -57,10 +57,6 @@
|
|||||||
"Name": "ShowKnownFileExt",
|
"Name": "ShowKnownFileExt",
|
||||||
"Value": true
|
"Value": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"Name": "DisableDragTray",
|
|
||||||
"Value": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"Name": "Hide3dObjects",
|
"Name": "Hide3dObjects",
|
||||||
"Value": true
|
"Value": true
|
||||||
|
|||||||
@@ -832,19 +832,6 @@
|
|||||||
"MinVersion": null,
|
"MinVersion": null,
|
||||||
"MaxVersion": null
|
"MaxVersion": null
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"FeatureId": "DisableDragTray",
|
|
||||||
"Label": "Disable 'Drag Tray' for sharing & moving files",
|
|
||||||
"ToolTip": "The Drag Tray is a new feature for sharing & moving files in Windows 11, it appears at the top of the screen when dragging files.",
|
|
||||||
"Category": "System",
|
|
||||||
"RegistryKey": "Disable_Share_Drag_Tray.reg",
|
|
||||||
"ApplyText": "Disabling Drag Tray",
|
|
||||||
"UndoLabel": "Enable 'Drag Tray' for sharing & moving files",
|
|
||||||
"ApplyUndoText": "Enabling Drag Tray",
|
|
||||||
"RegistryUndoKey": "Enable_Share_Drag_Tray.reg",
|
|
||||||
"MinVersion": 26200,
|
|
||||||
"MaxVersion": null
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"FeatureId": "RevertContextMenu",
|
"FeatureId": "RevertContextMenu",
|
||||||
"Label": "Use classic Windows 10 context menu style",
|
"Label": "Use classic Windows 10 context menu style",
|
||||||
|
|||||||
@@ -230,13 +230,6 @@
|
|||||||
"UndoLabel": "Disable dark theme for system and apps",
|
"UndoLabel": "Disable dark theme for system and apps",
|
||||||
"ApplyUndoText": "Disabling dark mode for system and apps"
|
"ApplyUndoText": "Disabling dark mode for system and apps"
|
||||||
},
|
},
|
||||||
"DisableDragTray": {
|
|
||||||
"Label": "Disable 'Drag Tray' for sharing & moving files",
|
|
||||||
"ToolTip": "The Drag Tray is a new feature for sharing & moving files in Windows 11, it appears at the top of the screen when dragging files.",
|
|
||||||
"ApplyText": "Disabling Drag Tray",
|
|
||||||
"UndoLabel": "Enable 'Drag Tray' for sharing & moving files",
|
|
||||||
"ApplyUndoText": "Enabling Drag Tray"
|
|
||||||
},
|
|
||||||
"RevertContextMenu": {
|
"RevertContextMenu": {
|
||||||
"Label": "Use classic Windows 10 context menu style",
|
"Label": "Use classic Windows 10 context menu style",
|
||||||
"ToolTip": "This will restore the classic Windows 10 style context menu, which is normally hidden behind the 'Show more options' entry in the new Windows 11 context menu.",
|
"ToolTip": "This will restore the classic Windows 10 style context menu, which is normally hidden behind the 'Show more options' entry in the new Windows 11 context menu.",
|
||||||
|
|||||||
@@ -230,13 +230,6 @@
|
|||||||
"UndoLabel": "Disabilita il tema scuro per sistema e app",
|
"UndoLabel": "Disabilita il tema scuro per sistema e app",
|
||||||
"ApplyUndoText": "Disabilitazione della modalità scura per sistema e app"
|
"ApplyUndoText": "Disabilitazione della modalità scura per sistema e app"
|
||||||
},
|
},
|
||||||
"DisableDragTray": {
|
|
||||||
"Label": "Disabilita 'Drag Tray' per condividere e spostare file",
|
|
||||||
"ToolTip": "Drag Tray è una nuova funzionalità di Windows 11 per condividere e spostare file; viene visualizzata nella parte superiore dello schermo quando trascini dei file.",
|
|
||||||
"ApplyText": "Disabilitazione di Drag Tray",
|
|
||||||
"UndoLabel": "Abilita 'Drag Tray' per condividere e spostare file",
|
|
||||||
"ApplyUndoText": "Abilitazione di Drag Tray"
|
|
||||||
},
|
|
||||||
"RevertContextMenu": {
|
"RevertContextMenu": {
|
||||||
"Label": "Usa lo stile del menu contestuale classico di Windows 10",
|
"Label": "Usa lo stile del menu contestuale classico di Windows 10",
|
||||||
"ToolTip": "Ripristina il menu contestuale nello stile classico di Windows 10, normalmente nascosto dietro la voce 'Mostra altre opzioni' del nuovo menu contestuale di Windows 11.",
|
"ToolTip": "Ripristina il menu contestuale nello stile classico di Windows 10, normalmente nascosto dietro la voce 'Mostra altre opzioni' del nuovo menu contestuale di Windows 11.",
|
||||||
|
|||||||
@@ -230,13 +230,6 @@
|
|||||||
"UndoLabel": "システムとアプリでダーク テーマを無効にする",
|
"UndoLabel": "システムとアプリでダーク テーマを無効にする",
|
||||||
"ApplyUndoText": "システムとアプリのダーク モードを無効にしています"
|
"ApplyUndoText": "システムとアプリのダーク モードを無効にしています"
|
||||||
},
|
},
|
||||||
"DisableDragTray": {
|
|
||||||
"Label": "ファイルの共有と移動用の「Drag Tray」を無効にする",
|
|
||||||
"ToolTip": "Drag Tray は Windows 11 でファイルを共有および移動するための新機能であり、ファイルをドラッグしたときに画面上部に表示されます。",
|
|
||||||
"ApplyText": "Drag Tray を無効にしています",
|
|
||||||
"UndoLabel": "ファイルの共有と移動用の「Drag Tray」を有効にする",
|
|
||||||
"ApplyUndoText": "Drag Tray を有効にしています"
|
|
||||||
},
|
|
||||||
"RevertContextMenu": {
|
"RevertContextMenu": {
|
||||||
"Label": "従来の Windows 10 スタイルのコンテキスト メニューを使用する",
|
"Label": "従来の Windows 10 スタイルのコンテキスト メニューを使用する",
|
||||||
"ToolTip": "新しい Windows 11 のコンテキスト メニューでは通常「その他のオプションを表示」項目の奥に隠されている、従来の Windows 10 スタイルのコンテキスト メニューを復元します。",
|
"ToolTip": "新しい Windows 11 のコンテキスト メニューでは通常「その他のオプションを表示」項目の奥に隠されている、従来の Windows 10 スタイルのコンテキスト メニューを復元します。",
|
||||||
|
|||||||
@@ -230,13 +230,6 @@
|
|||||||
"UndoLabel": "Donker thema voor Windows en apps uitschakelen",
|
"UndoLabel": "Donker thema voor Windows en apps uitschakelen",
|
||||||
"ApplyUndoText": "Donker thema voor Windows en apps uitschakelen"
|
"ApplyUndoText": "Donker thema voor Windows en apps uitschakelen"
|
||||||
},
|
},
|
||||||
"DisableDragTray": {
|
|
||||||
"Label": "'Drag Tray' voor het delen van bestanden uitschakelen",
|
|
||||||
"ToolTip": "Drag Tray is een nieuwe functie voor het delen en verplaatsen van bestanden in Windows 11. Deze verschijnt bovenaan het scherm wanneer je bestanden sleept.",
|
|
||||||
"ApplyText": "Drag Tray uitschakelen",
|
|
||||||
"UndoLabel": "'Drag Tray' voor het delen van bestanden inschakelen",
|
|
||||||
"ApplyUndoText": "Drag Tray inschakelen"
|
|
||||||
},
|
|
||||||
"RevertContextMenu": {
|
"RevertContextMenu": {
|
||||||
"Label": "Het klassieke contextmenu van Windows 10 gebruiken",
|
"Label": "Het klassieke contextmenu van Windows 10 gebruiken",
|
||||||
"ToolTip": "Herstelt het klassieke Windows 10-contextmenu, dat normaal achter 'Meer opties weergeven' in het nieuwe Windows 11-contextmenu verborgen zit.",
|
"ToolTip": "Herstelt het klassieke Windows 10-contextmenu, dat normaal achter 'Meer opties weergeven' in het nieuwe Windows 11-contextmenu verborgen zit.",
|
||||||
|
|||||||
@@ -230,13 +230,6 @@
|
|||||||
"UndoLabel": "Desabilitar tema escuro para o sistema e apps",
|
"UndoLabel": "Desabilitar tema escuro para o sistema e apps",
|
||||||
"ApplyUndoText": "Desabilitando modo escuro para o sistema e apps"
|
"ApplyUndoText": "Desabilitando modo escuro para o sistema e apps"
|
||||||
},
|
},
|
||||||
"DisableDragTray": {
|
|
||||||
"Label": "Desabilitar 'Drag Tray' para compartilhar e mover arquivos",
|
|
||||||
"ToolTip": "O Drag Tray é uma nova funcionalidade para compartilhar e mover arquivos no Windows 11, aparece no topo da tela ao arrastar arquivos.",
|
|
||||||
"ApplyText": "Desabilitando Drag Tray",
|
|
||||||
"UndoLabel": "Habilitar 'Drag Tray' para compartilhar e mover arquivos",
|
|
||||||
"ApplyUndoText": "Habilitando Drag Tray"
|
|
||||||
},
|
|
||||||
"RevertContextMenu": {
|
"RevertContextMenu": {
|
||||||
"Label": "Usar estilo clássico de menu de contexto do Windows 10",
|
"Label": "Usar estilo clássico de menu de contexto do Windows 10",
|
||||||
"ToolTip": "Isto restaurará o estilo clássico do menu de contexto do Windows 10, que normalmente fica oculto atrás da entrada 'Mostrar mais opções' no novo menu de contexto do Windows 11.",
|
"ToolTip": "Isto restaurará o estilo clássico do menu de contexto do Windows 10, que normalmente fica oculto atrás da entrada 'Mostrar mais opções' no novo menu de contexto do Windows 11.",
|
||||||
|
|||||||
@@ -230,13 +230,6 @@
|
|||||||
"UndoLabel": "禁用系统和应用的深色主题",
|
"UndoLabel": "禁用系统和应用的深色主题",
|
||||||
"ApplyUndoText": "正在禁用系统和应用的深色模式"
|
"ApplyUndoText": "正在禁用系统和应用的深色模式"
|
||||||
},
|
},
|
||||||
"DisableDragTray": {
|
|
||||||
"Label": "禁用用于共享和移动文件的拖放托盘",
|
|
||||||
"ToolTip": "拖放托盘是 Windows 11 用于共享和移动文件的新功能,会在拖动文件时出现在屏幕顶部。",
|
|
||||||
"ApplyText": "正在禁用拖放托盘",
|
|
||||||
"UndoLabel": "启用用于共享和移动文件的拖放托盘",
|
|
||||||
"ApplyUndoText": "正在启用拖放托盘"
|
|
||||||
},
|
|
||||||
"RevertContextMenu": {
|
"RevertContextMenu": {
|
||||||
"Label": "使用经典 Windows 10 右键菜单样式",
|
"Label": "使用经典 Windows 10 右键菜单样式",
|
||||||
"ToolTip": "恢复经典 Windows 10 风格的右键菜单。在 Windows 11 中,通常需要点击“显示更多选项”才能打开此菜单。",
|
"ToolTip": "恢复经典 Windows 10 风格的右键菜单。在 Windows 11 中,通常需要点击“显示更多选项”才能打开此菜单。",
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ Below is an overview of the key features and functionality offered by Win11Deblo
|
|||||||
|
|
||||||
#### System
|
#### System
|
||||||
|
|
||||||
- Disable the Drag Tray for sharing & moving files.
|
|
||||||
- Restore the old Windows 10 style context menu.
|
- Restore the old Windows 10 style context menu.
|
||||||
- Turn off Enhance Pointer Precision (mouse acceleration).
|
- Turn off Enhance Pointer Precision (mouse acceleration).
|
||||||
- Disable the Sticky Keys keyboard shortcut.
|
- Disable the Sticky Keys keyboard shortcut.
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -344,12 +344,12 @@ function Test-RegistryExecutableValueDataAllowed {
|
|||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Converts legacy absent value-only keys into scoped missing-value snapshots.
|
Filters unknown backup entries and converts legacy absent value-only keys.
|
||||||
|
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Uses only trusted feature plans. Empty absent-key snapshots at exact value-only
|
Uses trusted feature plans to warn and discard unknown values and keys, then
|
||||||
paths are converted in memory; authorized tree deletions and invalid snapshots
|
converts legacy absent keys into scoped missing-value snapshots. Retained data
|
||||||
remain unchanged for subsequent validation. The input snapshots are not modified.
|
still undergoes normal validation. The input snapshots are not modified.
|
||||||
#>
|
#>
|
||||||
function ConvertTo-CompatibleRegistryKeySnapshots {
|
function ConvertTo-CompatibleRegistryKeySnapshots {
|
||||||
param(
|
param(
|
||||||
@@ -362,9 +362,48 @@ function ConvertTo-CompatibleRegistryKeySnapshots {
|
|||||||
|
|
||||||
foreach ($snapshot in $RegistryKeys) {
|
foreach ($snapshot in $RegistryKeys) {
|
||||||
$normalizedPath = Get-NormalizedRegistryPathKey -Path $snapshot.Path
|
$normalizedPath = Get-NormalizedRegistryPathKey -Path $snapshot.Path
|
||||||
$plan = if ($normalizedPath) { $PlanMap[$normalizedPath] } else { $null }
|
# Invalid paths remain blocking validation errors.
|
||||||
|
if (-not $normalizedPath -or $snapshot.Path.IndexOf([char]0) -ge 0) {
|
||||||
|
$snapshot
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
$planMatch = Find-RegistryAllowListPlanMatch -NormalizedPath $normalizedPath -PlanMap $PlanMap
|
||||||
|
$values = @(
|
||||||
|
foreach ($value in @($snapshot.Values)) {
|
||||||
|
$valueName = Get-NormalizedRegistryValueName -ValueName $value.Name
|
||||||
|
if ($null -ne $planMatch -and
|
||||||
|
($valueName.IndexOf([char]0) -ge 0 -or
|
||||||
|
(Test-RegistryValueAllowedByPlan -PlanMatch $planMatch -ValueName $valueName))) {
|
||||||
|
$value
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$reference = Get-RegistryValueReferenceForError -SnapshotPath $snapshot.Path -ValueName $valueName
|
||||||
|
Write-Warning "Skipping unknown backup registry value '$reference'."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($null -eq $planMatch) {
|
||||||
|
if (@($snapshot.Values).Count -eq 0) {
|
||||||
|
Write-Warning "Skipping unknown backup registry key '$($snapshot.Path)'."
|
||||||
|
}
|
||||||
|
# Discard the entire unknown subtree, including any deletion request.
|
||||||
|
$null = @(ConvertTo-CompatibleRegistryKeySnapshots -RegistryKeys @($snapshot.SubKeys) -PlanMap @{})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
$subKeys = @(ConvertTo-CompatibleRegistryKeySnapshots -RegistryKeys @($snapshot.SubKeys) -PlanMap $PlanMap)
|
||||||
|
# An emptied snapshot must not become a key-creation or legacy deletion request.
|
||||||
|
if ($values.Count -eq 0 -and $subKeys.Count -eq 0 -and
|
||||||
|
(@($snapshot.Values).Count -gt 0 -or @($snapshot.SubKeys).Count -gt 0)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# Legacy conversion requires an exact plan; inherited subtree permissions do not qualify.
|
||||||
|
$plan = $PlanMap[$normalizedPath]
|
||||||
$convertAbsentKey = $snapshot.Exists -is [bool] -and -not $snapshot.Exists -and
|
$convertAbsentKey = $snapshot.Exists -is [bool] -and -not $snapshot.Exists -and
|
||||||
@($snapshot.Values).Count -eq 0 -and @($snapshot.SubKeys).Count -eq 0 -and
|
$values.Count -eq 0 -and $subKeys.Count -eq 0 -and
|
||||||
$null -ne $plan -and -not $plan.CaptureAllValues -and -not $plan.IncludeSubKeys -and
|
$null -ne $plan -and -not $plan.CaptureAllValues -and -not $plan.IncludeSubKeys -and
|
||||||
$plan.ValueNames.Count -gt 0 -and
|
$plan.ValueNames.Count -gt 0 -and
|
||||||
-not (Test-RegistryKeyDeletionAllowed -NormalizedPath $normalizedPath -PlanMap $PlanMap)
|
-not (Test-RegistryKeyDeletionAllowed -NormalizedPath $normalizedPath -PlanMap $PlanMap)
|
||||||
@@ -374,8 +413,8 @@ function ConvertTo-CompatibleRegistryKeySnapshots {
|
|||||||
# RemoveEmptyKey is derived here and is deliberately not read by normalization.
|
# RemoveEmptyKey is derived here and is deliberately not read by normalization.
|
||||||
$removeEmptyKey = $originallyAbsent -and ($snapshot.Exists -or $convertAbsentKey) -and
|
$removeEmptyKey = $originallyAbsent -and ($snapshot.Exists -or $convertAbsentKey) -and
|
||||||
$null -ne $plan -and -not $plan.CaptureAllValues -and -not $plan.IncludeSubKeys -and
|
$null -ne $plan -and -not $plan.CaptureAllValues -and -not $plan.IncludeSubKeys -and
|
||||||
@($snapshot.SubKeys).Count -eq 0 -and
|
$subKeys.Count -eq 0 -and
|
||||||
@($snapshot.Values | Where-Object { [bool]$_.Exists }).Count -eq 0
|
@($values | Where-Object { [bool]$_.Exists }).Count -eq 0
|
||||||
|
|
||||||
[PSCustomObject]@{
|
[PSCustomObject]@{
|
||||||
Path = $snapshot.Path
|
Path = $snapshot.Path
|
||||||
@@ -387,9 +426,9 @@ function ConvertTo-CompatibleRegistryKeySnapshots {
|
|||||||
foreach ($valueName in @($plan.ValueNames | Sort-Object)) {
|
foreach ($valueName in @($plan.ValueNames | Sort-Object)) {
|
||||||
[PSCustomObject]@{ Name = $valueName; Exists = $false; Kind = $null; Data = $null }
|
[PSCustomObject]@{ Name = $valueName; Exists = $false; Kind = $null; Data = $null }
|
||||||
}
|
}
|
||||||
} else { $snapshot.Values }
|
} else { $values }
|
||||||
)
|
)
|
||||||
SubKeys = @(ConvertTo-CompatibleRegistryKeySnapshots -RegistryKeys @($snapshot.SubKeys) -PlanMap $PlanMap)
|
SubKeys = $subKeys
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,8 +439,7 @@ function ConvertTo-CompatibleRegistryKeySnapshots {
|
|||||||
registry-backed apply or undo key relevant to the requested direction.
|
registry-backed apply or undo key relevant to the requested direction.
|
||||||
|
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Appends a translated error to the caller-supplied Errors list for any feature ID that
|
Warns and skips feature IDs that are no longer in the current catalog.
|
||||||
isn't in the current catalog, rather than failing the whole validation outright.
|
|
||||||
#>
|
#>
|
||||||
function Get-SelectedRegistryFeaturesForBackupValidation {
|
function Get-SelectedRegistryFeaturesForBackupValidation {
|
||||||
param(
|
param(
|
||||||
@@ -424,7 +462,7 @@ function Get-SelectedRegistryFeaturesForBackupValidation {
|
|||||||
$selectedRegistryFeatures = New-Object System.Collections.Generic.List[object]
|
$selectedRegistryFeatures = New-Object System.Collections.Generic.List[object]
|
||||||
foreach ($featureId in @($SelectedFeatureIds)) {
|
foreach ($featureId in @($SelectedFeatureIds)) {
|
||||||
if (-not $script:Features.ContainsKey($featureId)) {
|
if (-not $script:Features.ContainsKey($featureId)) {
|
||||||
$Errors.Add((Get-Translation -Key 'BackupFeatureNotInCatalog' -FormatArgs @($featureId)))
|
Write-Warning "Skipping unknown backup feature '$featureId'."
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ param (
|
|||||||
[switch]$ClearStartAllUsers,
|
[switch]$ClearStartAllUsers,
|
||||||
[string]$ReplaceStartAllUsers,
|
[string]$ReplaceStartAllUsers,
|
||||||
[switch]$RevertContextMenu,
|
[switch]$RevertContextMenu,
|
||||||
[switch]$DisableDragTray,
|
|
||||||
[switch]$DisableMouseAcceleration,
|
[switch]$DisableMouseAcceleration,
|
||||||
[switch]$DisableStickyKeys,
|
[switch]$DisableStickyKeys,
|
||||||
[switch]$DisableWindowSnapping,
|
[switch]$DisableWindowSnapping,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ BeforeAll {
|
|||||||
Describe 'Registry backup deletion permissions' {
|
Describe 'Registry backup deletion permissions' {
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
$script:Params = @{}
|
$script:Params = @{}
|
||||||
|
Mock Write-Warning {}
|
||||||
$script:RegfilesPath = Join-Path $PSScriptRoot '..\Regfiles'
|
$script:RegfilesPath = Join-Path $PSScriptRoot '..\Regfiles'
|
||||||
$script:Features = @{}
|
$script:Features = @{}
|
||||||
foreach ($feature in $script:FeatureCatalog.Features) {
|
foreach ($feature in $script:FeatureCatalog.Features) {
|
||||||
@@ -26,6 +27,116 @@ Describe 'Registry backup deletion permissions' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It 'skips retired Drag Tray data in an existing backup (undo: <Undo>, absent key: <Absent>)' -ForEach @(
|
||||||
|
@{ Undo = $false; Absent = $false }
|
||||||
|
@{ Undo = $true; Absent = $false }
|
||||||
|
@{ Undo = $false; Absent = $true }
|
||||||
|
) {
|
||||||
|
$backup = [PSCustomObject]@{
|
||||||
|
Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'
|
||||||
|
SelectedFeatures = @(if (-not $Undo) { 'DisableDragTray' })
|
||||||
|
SelectedUndoFeatures = @(if ($Undo) { 'DisableDragTray' })
|
||||||
|
RegistryKeys = @([PSCustomObject]@{
|
||||||
|
Path = 'HKEY_USERS\Default\Software\Microsoft\Windows\CurrentVersion\CDP'
|
||||||
|
Exists = -not $Absent
|
||||||
|
Values = @(if (-not $Absent) { [PSCustomObject]@{ Name = 'DragTrayEnabled'; Exists = $true; Kind = 'DWord'; Data = 1 } })
|
||||||
|
SubKeys = @()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalized = ConvertTo-NormalizedRegistryBackup -Backup $backup
|
||||||
|
|
||||||
|
$normalized.RegistryKeys | Should -BeNullOrEmpty
|
||||||
|
# Restore normalizes a second time, so skipping must be idempotent.
|
||||||
|
(ConvertTo-NormalizedRegistryBackup -Backup $normalized).RegistryKeys | Should -BeNullOrEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'warns for each unknown value beside a retired value' {
|
||||||
|
$snapshot = [PSCustomObject]@{
|
||||||
|
Path = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\CDP'
|
||||||
|
Exists = $true
|
||||||
|
Values = @(
|
||||||
|
[PSCustomObject]@{ Name = 'DragTrayEnabled'; Exists = $true; Kind = 'DWord'; Data = 1 }
|
||||||
|
[PSCustomObject]@{ Name = 'OtherValue'; Exists = $true; Kind = 'DWord'; Data = 1 }
|
||||||
|
)
|
||||||
|
SubKeys = @()
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalized = @(ConvertTo-CompatibleRegistryKeySnapshots -RegistryKeys @($snapshot) -PlanMap @{})
|
||||||
|
|
||||||
|
$normalized | Should -BeNullOrEmpty
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*DragTrayEnabled*' }
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*OtherValue*' }
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'ignores additional unknown features without retirement definitions' {
|
||||||
|
$backup = [PSCustomObject]@{
|
||||||
|
Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'
|
||||||
|
SelectedFeatures = @('RetiredOne'); SelectedUndoFeatures = @('RetiredTwo')
|
||||||
|
RegistryKeys = @([PSCustomObject]@{
|
||||||
|
Path = 'HKEY_USERS\Default\Software\Retired'; Exists = $true; SubKeys = @()
|
||||||
|
Values = @('First', 'Second', 'Third' | ForEach-Object {
|
||||||
|
[PSCustomObject]@{ Name = $_; Exists = $true; Kind = 'DWord'; Data = 1 }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
(ConvertTo-NormalizedRegistryBackup -Backup $backup).RegistryKeys | Should -BeNullOrEmpty
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like "*feature 'RetiredOne'*" }
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like "*feature 'RetiredTwo'*" }
|
||||||
|
Should -Invoke Write-Warning -Times 3 -Exactly -ParameterFilter { $Message -like '*registry value*' }
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'preserves known values while dropping unknown values and child keys' {
|
||||||
|
$path = 'HKEY_USERS\Default\Control Panel\Desktop'
|
||||||
|
$backup = [PSCustomObject]@{
|
||||||
|
Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'
|
||||||
|
SelectedFeatures = @('DisableAnimations', 'UnknownFeature')
|
||||||
|
RegistryKeys = @([PSCustomObject]@{
|
||||||
|
Path = $path; Exists = $true
|
||||||
|
Values = @(
|
||||||
|
[PSCustomObject]@{ Name = 'UserPreferencesMask'; Exists = $true; Kind = 'Binary'; Data = @(144, 18, 7, 128, 16, 0, 0, 0) }
|
||||||
|
[PSCustomObject]@{ Name = 'OldSetting'; Exists = $true; Kind = 'Invalid'; Data = 'ignored' }
|
||||||
|
)
|
||||||
|
SubKeys = @([PSCustomObject]@{
|
||||||
|
Path = "$path\OldChild"; Exists = $true; SubKeys = @()
|
||||||
|
Values = @([PSCustomObject]@{ Name = ''; Exists = $true; Kind = 'String'; Data = 'ignored' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalized = ConvertTo-NormalizedRegistryBackup -Backup $backup
|
||||||
|
$normalized.RegistryKeys | Should -HaveCount 1
|
||||||
|
$normalized.RegistryKeys[0].Values | Should -HaveCount 1
|
||||||
|
$normalized.RegistryKeys[0].Values[0].Name | Should -Be 'UserPreferencesMask'
|
||||||
|
$normalized.RegistryKeys[0].SubKeys | Should -BeNullOrEmpty
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*OldSetting*' }
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*OldChild*(Default)*' }
|
||||||
|
|
||||||
|
$backup.RegistryKeys[0].Values[0].Data = @(256)
|
||||||
|
Mock Write-Error {}
|
||||||
|
{ ConvertTo-NormalizedRegistryBackup -Backup $backup } | Should -Throw '*Validation failed*'
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'drops an emptied known key without creating or deleting it (exists: <Exists>)' -ForEach @(
|
||||||
|
@{ Exists = $true }
|
||||||
|
@{ Exists = $false }
|
||||||
|
) {
|
||||||
|
$backup = [PSCustomObject]@{
|
||||||
|
Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'
|
||||||
|
SelectedFeatures = @('DisableAnimations')
|
||||||
|
RegistryKeys = @([PSCustomObject]@{
|
||||||
|
Path = 'HKEY_USERS\Default\Control Panel\Desktop'; Exists = $Exists; SubKeys = @()
|
||||||
|
Values = @([PSCustomObject]@{ Name = 'OldSetting'; Exists = $false })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalized = ConvertTo-NormalizedRegistryBackup -Backup $backup
|
||||||
|
$normalized.RegistryKeys | Should -BeNullOrEmpty
|
||||||
|
(ConvertTo-NormalizedRegistryBackup -Backup $normalized).RegistryKeys | Should -BeNullOrEmpty
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*OldSetting*' }
|
||||||
|
}
|
||||||
|
|
||||||
It 'rejects deletion of a key that <FeatureId> only changes values under' -ForEach @(
|
It 'rejects deletion of a key that <FeatureId> only changes values under' -ForEach @(
|
||||||
@{ FeatureId = 'DisableAnimations'; Path = 'HKEY_USERS\Default\Control Panel\Desktop' }
|
@{ FeatureId = 'DisableAnimations'; Path = 'HKEY_USERS\Default\Control Panel\Desktop' }
|
||||||
@{ FeatureId = 'DisableLocationServices'; Path = 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors' }
|
@{ FeatureId = 'DisableLocationServices'; Path = 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors' }
|
||||||
@@ -207,8 +318,8 @@ Describe 'Executable registry backup values' {
|
|||||||
$desktop = [PSCustomObject]@{ Path = 'HKEY_USERS\Default\Control Panel\Desktop'; Exists = $true; Values = @(); SubKeys = @() }
|
$desktop = [PSCustomObject]@{ Path = 'HKEY_USERS\Default\Control Panel\Desktop'; Exists = $true; Values = @(); SubKeys = @() }
|
||||||
$backup = [PSCustomObject]@{
|
$backup = [PSCustomObject]@{
|
||||||
Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'; SelectedFeatures = @('DisableAnimations')
|
Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'; SelectedFeatures = @('DisableAnimations')
|
||||||
RegistryKeys = @($desktop, [PSCustomObject]@{
|
RegistryKeys = @([PSCustomObject]@{
|
||||||
Path = 'HKEY_USERS\Default\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce'; Exists = $true; Values = @(); SubKeys = @($desktop)
|
Path = $desktop.Path; Exists = $true; Values = @(); SubKeys = @($desktop)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,14 +422,16 @@ Describe 'Legacy absent-key backup compatibility' {
|
|||||||
(Get-Content -LiteralPath $filePath -Raw) | Should -Be $originalContent
|
(Get-Content -LiteralPath $filePath -Raw) | Should -Be $originalContent
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'rejects an unknown absent-key path instead of converting it' {
|
It 'ignores an unknown absent-key path instead of converting or deleting it' {
|
||||||
|
Mock Write-Warning {}
|
||||||
$backup = [PSCustomObject]@{
|
$backup = [PSCustomObject]@{
|
||||||
Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'
|
Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'
|
||||||
SelectedFeatures = @('DisableAnimations')
|
SelectedFeatures = @('DisableAnimations')
|
||||||
RegistryKeys = @([PSCustomObject]@{ Path = 'HKEY_USERS\Default\Software\NotAllowedHere'; Exists = $false; Values = @(); SubKeys = @() })
|
RegistryKeys = @([PSCustomObject]@{ Path = 'HKEY_USERS\Default\Software\NotAllowedHere'; Exists = $false; Values = @(); SubKeys = @() })
|
||||||
}
|
}
|
||||||
|
|
||||||
{ ConvertTo-NormalizedRegistryBackup -Backup $backup } | Should -Throw '*unexpected registry path*'
|
(ConvertTo-NormalizedRegistryBackup -Backup $backup).RegistryKeys | Should -BeNullOrEmpty
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*NotAllowedHere*' }
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'imports a legacy value-only backup for <Target> using the correct profile paths' -ForEach @(
|
It 'imports a legacy value-only backup for <Target> using the correct profile paths' -ForEach @(
|
||||||
@@ -384,7 +497,8 @@ Describe 'Legacy absent-key backup compatibility' {
|
|||||||
Should -Invoke Get-RegistryBackupCapturePlans -Times 1 -Exactly
|
Should -Invoke Get-RegistryBackupCapturePlans -Times 1 -Exactly
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'rejects an absent value-only key containing subkeys' {
|
It 'skips an unknown child and its emptied absent parent without requesting deletion' {
|
||||||
|
Mock Write-Warning {}
|
||||||
$path = 'HKEY_USERS\Default\Control Panel\Desktop'
|
$path = 'HKEY_USERS\Default\Control Panel\Desktop'
|
||||||
$backup = [PSCustomObject]@{
|
$backup = [PSCustomObject]@{
|
||||||
Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'
|
Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'
|
||||||
@@ -395,8 +509,11 @@ Describe 'Legacy absent-key backup compatibility' {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
{ ConvertTo-NormalizedRegistryBackup -Backup $backup } | Should -Throw '*Validation failed*'
|
$normalized = ConvertTo-NormalizedRegistryBackup -Backup $backup
|
||||||
Should -Invoke Write-Error -Times 1 -Exactly -ParameterFilter { $Message -like '*unauthorized registry key deletion*' }
|
|
||||||
|
$normalized.RegistryKeys | Should -BeNullOrEmpty
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -eq "Skipping unknown backup registry key '$path\Child'." }
|
||||||
|
Should -Invoke Write-Error -Times 0 -Exactly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,17 +719,35 @@ Describe 'Executable registry restore confirmation' {
|
|||||||
Should -Invoke Invoke-WithLoadedRestoreHive -Times 0 -Exactly
|
Should -Invoke Invoke-WithLoadedRestoreHive -Times 0 -Exactly
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'does not permit overriding <Case>' -ForEach @(
|
It 'skips <Case> with a warning and never restores it or asks for confirmation' -ForEach @(
|
||||||
@{ Case = 'an unauthorized path' }
|
@{ Case = 'an unauthorized path' }
|
||||||
@{ Case = 'an unauthorized value name' }
|
@{ Case = 'an unauthorized value name' }
|
||||||
|
) {
|
||||||
|
Mock Write-Warning {}
|
||||||
|
$backup = New-ExecutableTestBackup
|
||||||
|
if ($Case -eq 'an unauthorized path') {
|
||||||
|
$backup.RegistryKeys[0].Path = 'HKEY_LOCAL_MACHINE\Software\Unrelated'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$backup.RegistryKeys[0].Values[0].Name = 'Unrelated'
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = Restore-RegistryBackupState -Backup $backup -ConfirmUntrustedValues { throw 'Confirmation must not be reached' }
|
||||||
|
|
||||||
|
$result.Result | Should -BeTrue
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like 'Skipping unknown backup registry value *Unrelated*' }
|
||||||
|
Should -Invoke Write-Error -Times 0 -Exactly
|
||||||
|
Should -Invoke Restore-RegistryKeySnapshot -Times 0 -Exactly
|
||||||
|
Should -Invoke Invoke-WithLoadedRestoreHive -Times 1 -Exactly -ParameterFilter { @($ArgumentObject.RegistryKeys).Count -eq 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'does not permit overriding <Case>' -ForEach @(
|
||||||
@{ Case = 'an unauthorized tree deletion' }
|
@{ Case = 'an unauthorized tree deletion' }
|
||||||
@{ Case = 'an invalid kind' }
|
@{ Case = 'an invalid kind' }
|
||||||
@{ Case = 'a misplaced child' }
|
@{ Case = 'a misplaced child' }
|
||||||
) {
|
) {
|
||||||
$backup = New-ExecutableTestBackup
|
$backup = New-ExecutableTestBackup
|
||||||
switch ($Case) {
|
switch ($Case) {
|
||||||
'an unauthorized path' { $backup.RegistryKeys[0].Path = 'HKEY_LOCAL_MACHINE\Software\Unrelated' }
|
|
||||||
'an unauthorized value name' { $backup.RegistryKeys[0].Values[0].Name = 'Unrelated' }
|
|
||||||
'an unauthorized tree deletion' { $backup.RegistryKeys[0].Exists = $false }
|
'an unauthorized tree deletion' { $backup.RegistryKeys[0].Exists = $false }
|
||||||
'an invalid kind' { $backup.RegistryKeys[0].Values[0].Kind = '99' }
|
'an invalid kind' { $backup.RegistryKeys[0].Values[0].Kind = '99' }
|
||||||
'a misplaced child' { $backup.RegistryKeys[0].SubKeys = (New-ExecutableTestBackup -Path 'HKEY_CLASSES_ROOT\ms-gamebarservices\shell\open\command').RegistryKeys }
|
'a misplaced child' { $backup.RegistryKeys[0].SubKeys = (New-ExecutableTestBackup -Path 'HKEY_CLASSES_ROOT\ms-gamebarservices\shell\open\command').RegistryKeys }
|
||||||
|
|||||||
@@ -49,10 +49,12 @@ Describe 'Test-RegistryBackupMatchesSelectedFeatures' {
|
|||||||
$script:CapturePlanCalls | Should -Be @($true)
|
$script:CapturePlanCalls | Should -Be @($true)
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'reports unknown selected features without deriving capture plans' {
|
It 'warns and skips unknown selected features without deriving capture plans' {
|
||||||
|
Mock Write-Warning {}
|
||||||
$errors = @(Test-RegistryBackupMatchesSelectedFeatures -SelectedFeatureIds @('UnknownFeature') -SelectedUndoFeatureIds @() -Target 'CurrentUser' -RegistryKeys @())
|
$errors = @(Test-RegistryBackupMatchesSelectedFeatures -SelectedFeatureIds @('UnknownFeature') -SelectedUndoFeatureIds @() -Target 'CurrentUser' -RegistryKeys @())
|
||||||
|
|
||||||
$errors | Should -Contain "Selected feature 'UnknownFeature' was not found in the current feature catalog."
|
$errors | Should -BeNullOrEmpty
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*UnknownFeature*' }
|
||||||
$script:CapturePlanCalls | Should -BeNullOrEmpty
|
$script:CapturePlanCalls | Should -BeNullOrEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,13 +79,15 @@ Describe 'Get-SelectedRegistryFeaturesForBackupValidation' {
|
|||||||
$valueNames.Contains('mode') | Should -BeTrue
|
$valueNames.Contains('mode') | Should -BeTrue
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'selects registry-backed apply features and reports unknown IDs' {
|
It 'selects registry-backed apply features and warns for unknown IDs' {
|
||||||
|
Mock Write-Warning {}
|
||||||
$errors = New-Object System.Collections.Generic.List[string]
|
$errors = New-Object System.Collections.Generic.List[string]
|
||||||
|
|
||||||
$result = @(Get-SelectedRegistryFeaturesForBackupValidation -SelectedFeatureIds @('ApplyFeature', 'CustomFeature', 'MissingFeature') -IsUndoFeature:$false -Errors $errors)
|
$result = @(Get-SelectedRegistryFeaturesForBackupValidation -SelectedFeatureIds @('ApplyFeature', 'CustomFeature', 'MissingFeature') -IsUndoFeature:$false -Errors $errors)
|
||||||
|
|
||||||
$result.Id | Should -Be 'ApplyFeature'
|
$result.Id | Should -Be 'ApplyFeature'
|
||||||
$errors | Should -Contain "Selected feature 'MissingFeature' was not found in the current feature catalog."
|
$errors | Should -BeNullOrEmpty
|
||||||
|
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*MissingFeature*' }
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'uses undo registry keys and falls back to apply keys when needed' {
|
It 'uses undo registry keys and falls back to apply keys when needed' {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ Describe 'Import-RegistryBackup' {
|
|||||||
It 'parses and normalizes registry snapshots from a real backup structure' {
|
It 'parses and normalizes registry snapshots from a real backup structure' {
|
||||||
Mock Test-UserNameMatch { $true }
|
Mock Test-UserNameMatch { $true }
|
||||||
Mock Get-RegistryBackupValidationPlanMap { @{} }
|
Mock Get-RegistryBackupValidationPlanMap { @{} }
|
||||||
|
Mock ConvertTo-CompatibleRegistryKeySnapshots { param($RegistryKeys) $RegistryKeys }
|
||||||
Mock Test-RegistryBackupAgainstAllowList { @() }
|
Mock Test-RegistryBackupAgainstAllowList { @() }
|
||||||
|
|
||||||
$result = Import-RegistryBackup -FilePath (Join-Path $script:JsonFixturePath 'RegistryBackup.RealStructure.json')
|
$result = Import-RegistryBackup -FilePath (Join-Path $script:JsonFixturePath 'RegistryBackup.RealStructure.json')
|
||||||
@@ -61,6 +62,7 @@ Describe 'ConvertTo-NormalizedRegistryBackup' {
|
|||||||
BeforeEach {
|
BeforeEach {
|
||||||
$script:Features = @{ Example = [PSCustomObject]@{ FeatureId = 'Example'; RegistryKey = 'Example.reg' } }
|
$script:Features = @{ Example = [PSCustomObject]@{ FeatureId = 'Example'; RegistryKey = 'Example.reg' } }
|
||||||
Mock Get-RegistryBackupValidationPlanMap { @{} }
|
Mock Get-RegistryBackupValidationPlanMap { @{} }
|
||||||
|
Mock ConvertTo-CompatibleRegistryKeySnapshots { param($RegistryKeys) $RegistryKeys }
|
||||||
Mock Test-RegistryBackupAgainstAllowList { @() }
|
Mock Test-RegistryBackupAgainstAllowList { @() }
|
||||||
Mock Write-Error {}
|
Mock Write-Error {}
|
||||||
}
|
}
|
||||||
@@ -122,6 +124,7 @@ Describe 'Restore-RegistryBackupState' {
|
|||||||
Mock Test-UserNameMatch { $true }
|
Mock Test-UserNameMatch { $true }
|
||||||
Mock Write-Error {}
|
Mock Write-Error {}
|
||||||
Mock Get-RegistryBackupValidationPlanMap { @{} }
|
Mock Get-RegistryBackupValidationPlanMap { @{} }
|
||||||
|
Mock ConvertTo-CompatibleRegistryKeySnapshots { param($RegistryKeys) $RegistryKeys }
|
||||||
Mock Test-RegistryBackupAgainstAllowList { @() }
|
Mock Test-RegistryBackupAgainstAllowList { @() }
|
||||||
$script:backup = [PSCustomObject]@{
|
$script:backup = [PSCustomObject]@{
|
||||||
Version = '1.0'; BackupType = 'RegistryState'; Target = 'CurrentUser:Tester'; SelectedFeatures = @('Example')
|
Version = '1.0'; BackupType = 'RegistryState'; Target = 'CurrentUser:Tester'; SelectedFeatures = @('Example')
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ param (
|
|||||||
[switch]$ClearStartAllUsers,
|
[switch]$ClearStartAllUsers,
|
||||||
[string]$ReplaceStartAllUsers,
|
[string]$ReplaceStartAllUsers,
|
||||||
[switch]$RevertContextMenu,
|
[switch]$RevertContextMenu,
|
||||||
[switch]$DisableDragTray,
|
|
||||||
[switch]$DisableMouseAcceleration,
|
[switch]$DisableMouseAcceleration,
|
||||||
[switch]$DisableStickyKeys,
|
[switch]$DisableStickyKeys,
|
||||||
[switch]$DisableWindowSnapping,
|
[switch]$DisableWindowSnapping,
|
||||||
|
|||||||
Reference in New Issue
Block a user