From 2f828735a87f98ba87b4fc826823d1482d4f2db2 Mon Sep 17 00:00:00 2001 From: undergroundwires Date: Sat, 22 Jun 2024 14:01:06 +0200 Subject: [PATCH] win: fix errors due to missing Edge uninstaller If Edge is uninstalled using an existing installer, it may delete other installers. When the script attempts to use these deleted installers, it results in an error: `The system cannot find the file specified.`. This commit addresses the issue by checking for the existence of the uninstaller during the iteration and handling cases where it is missing. --- src/application/collections/windows.yaml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/application/collections/windows.yaml b/src/application/collections/windows.yaml index 57213eae..124f7552 100644 --- a/src/application/collections/windows.yaml +++ b/src/application/collections/windows.yaml @@ -19301,17 +19301,22 @@ actions: valueName: AllowUninstall dataType: REG_DWORD data: "1" - deleteOnRevert: 'true' # Missing key since Windows 10 21H2, Windows 11 21H2 + deleteOnRevert: 'true' # Missing key since Windows 10 21H2, Windows 11 21H2 - function: RunPowerShell parameters: + codeComment: Uninstall running the official uninstaller code: |- - $installer = (Get-ChildItem "$($env:ProgramFiles)*\Microsoft\Edge\Application\*\Installer\setup.exe") - if (!$installer) { + $installers = (Get-ChildItem "$($env:ProgramFiles)*\Microsoft\Edge\Application\*\Installer\setup.exe") + if (!$installers) { Write-Host 'Installer not found. Microsoft Edge may already be uninstalled.' } else { - $installer | ForEach-Object { - $uninstallerPath = $_.FullName + foreach ($installer in $installers) { + $uninstallerPath = $installer.FullName + if (-Not (Test-Path "$uninstallerPath")) { + Write-Host "Installer not found at `"$uninstallerPath`". Microsoft Edge may already be uninstalled." + continue + } $installerArguments = @("--uninstall", "--system-level", "--verbose-logging", "--force-uninstall") Write-Output "Uninstalling through uninstaller: $uninstallerPath" $process = Start-Process -FilePath "$uninstallerPath" -ArgumentList $installerArguments -Wait -PassThru @@ -19322,6 +19327,7 @@ actions: } } } + revertCodeComment: Download and run the official uninstaller revertCode: |- $edgeExePath = Get-ChildItem -Path "$($env:ProgramFiles)*\Microsoft\Edge\Application" -Filter 'msedge.exe' -Recurse if ($edgeExePath) {