mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-08-23 07:56:31 +00:00
fix(system): correct service, update repair, and legacy imports (#4966)
* fix(system): correct sc.exe argument syntax, reg deletion, and ipv6 dns guard * fix(impex): exclude legacy Install metadata from flattened import * fix(service): throw on non-zero LASTEXITCODE from sc.exe config * refactor(dns): revert unnecessary ipv6 guard per review feedback * test(impex): cover legacy config imports --------- Co-authored-by: WinUtil Contributor <contributor@winutil.local> Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
co-authored by
WinUtil Contributor
Chris Titus
parent
b8b81edcdb
commit
4b2fe55a7a
@@ -33,7 +33,10 @@ Function Set-WinUtilService {
|
||||
|
||||
# Service exists, proceed with changing properties -- while handling auto delayed start for PWSH 5
|
||||
if (($PSVersionTable.PSVersion.Major -lt 7) -and ($StartupType -eq "AutomaticDelayedStart")) {
|
||||
sc.exe config $Name start=delayed-auto
|
||||
sc.exe config $Name start= delayed-auto
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "sc.exe config failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
} else {
|
||||
$service | Set-Service -StartupType $StartupType -ErrorAction Stop
|
||||
}
|
||||
|
||||
@@ -114,9 +114,9 @@ function Invoke-WPFFixesUpdate {
|
||||
if (Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate") {
|
||||
Write-Progress -Id 0 -Activity "Repairing Windows Update" -Status "Removing WSUS client settings..." -PercentComplete 60
|
||||
Write-Progress -Id 6 -ParentId 0 -Activity "Removing WSUS client settings" -PercentComplete 0
|
||||
Start-Process -NoNewWindow -FilePath "REG" -ArgumentList "DELETE", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate", "/v", "AccountDomainSid", "/f" -RedirectStandardError "NUL"
|
||||
Start-Process -NoNewWindow -FilePath "REG" -ArgumentList "DELETE", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate", "/v", "PingID", "/f" -RedirectStandardError "NUL"
|
||||
Start-Process -NoNewWindow -FilePath "REG" -ArgumentList "DELETE", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate", "/v", "SusClientId", "/f" -RedirectStandardError "NUL"
|
||||
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" -Name "AccountDomainSid" -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" -Name "PingID" -ErrorAction SilentlyContinue
|
||||
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" -Name "SusClientId" -ErrorAction SilentlyContinue
|
||||
Write-Progress -Id 6 -ParentId 0 -Activity "Removing WSUS client settings" -Status "Completed" -PercentComplete 100
|
||||
}
|
||||
|
||||
|
||||
@@ -73,9 +73,17 @@ function Invoke-WPFImpex {
|
||||
Write-Error "Failed to load the JSON file from the specified path or URL: $_"
|
||||
return
|
||||
}
|
||||
# TODO how to handle old style? detected json type then flatten it in a func?
|
||||
# $flattenedJson = $jsonFile.PSObject.Properties.Where({ $_.Name -ne "Install" }).ForEach({ $_.Value })
|
||||
$flattenedJson = $jsonFile
|
||||
if ($null -ne $jsonFile -and $jsonFile.PSObject.Properties['Install']) {
|
||||
Write-WinUtilLog -Component "Impex" -Message "Detected legacy WinUtil config structure; flattening import object."
|
||||
$flattenedJson = @()
|
||||
foreach ($prop in $jsonFile.PSObject.Properties) {
|
||||
if ($prop.Name -ne "Install" -and $null -ne $prop.Value) {
|
||||
$flattenedJson += @($prop.Value)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$flattenedJson = $jsonFile
|
||||
}
|
||||
|
||||
if (-not $flattenedJson) {
|
||||
[System.Windows.MessageBox]::Show(
|
||||
|
||||
@@ -271,6 +271,30 @@ Describe "Invoke-WPFImpex import selection state" {
|
||||
Should -Invoke -CommandName Write-Error -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It "imports legacy selection groups without treating Install metadata as a selection" {
|
||||
$legacyConfigPath = Join-Path $TestDrive "legacy-config.json"
|
||||
[ordered]@{
|
||||
Install = @(
|
||||
[pscustomobject]@{
|
||||
winget = "Git.Git"
|
||||
choco = "git"
|
||||
}
|
||||
)
|
||||
WPFInstall = @("WPFInstallGit")
|
||||
WPFTweaks = @("WPFTweaksTelemetry")
|
||||
WPFToggle = @("WPFToggleDarkMode")
|
||||
WPFFeature = @("WPFFeatureSandbox")
|
||||
} | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath $legacyConfigPath
|
||||
|
||||
Invoke-WPFImpex -type "import" -Config $legacyConfigPath
|
||||
|
||||
@($script:sync.selectedApps) | Should -Be @("WPFInstallGit")
|
||||
@($script:sync.selectedTweaks) | Should -Be @("WPFTweaksTelemetry")
|
||||
@($script:sync.selectedToggles) | Should -Be @("WPFToggleDarkMode")
|
||||
@($script:sync.selectedFeatures) | Should -Be @("WPFFeatureSandbox")
|
||||
Should -Invoke -CommandName Write-Error -Times 0 -Exactly
|
||||
}
|
||||
|
||||
It "preserves selections and does not reset the UI after an invalid import" {
|
||||
$script:sync.selectedApps.Add("WPFInstallExisting")
|
||||
$script:sync.selectedTweaks.Add("WPFTweaksExisting")
|
||||
|
||||
Reference in New Issue
Block a user