improve uninstalling apps to show errors and exit if taking ownership fails #51

This commit is contained in:
undergroundwires
2021-01-08 01:08:09 +01:00
parent c299e95bc6
commit 72e925fb6f

View File

@@ -4150,8 +4150,8 @@ functions:
$directories = @($package.InstallLocation, \"$env:LOCALAPPDATA\Packages\$($package.PackageFamilyName)\"); $directories = @($package.InstallLocation, \"$env:LOCALAPPDATA\Packages\$($package.PackageFamilyName)\");
foreach($dir in $directories) { foreach($dir in $directories) {
if ( !$dir -Or !(Test-Path \"$dir\") ) { continue; } if ( !$dir -Or !(Test-Path \"$dir\") ) { continue; }
cmd /c takeown /f \"$dir\" /r /d y | Out-Null; cmd /c ('takeown /f \"' + $dir + '\" /r /d y 1> nul'); if($LASTEXITCODE) { throw 'Failed to take ownership'; }
cmd /c icacls \"$dir\" /grant administrators:F /t | Out-Null; cmd /c ('icacls \"' + $dir + '\" /grant administrators:F /t 1> nul'); if($LASTEXITCODE) { throw 'Failed to take ownership'; }
$files = Get-ChildItem -File -Path $dir -Recurse -Force; $files = Get-ChildItem -File -Path $dir -Recurse -Force;
foreach($file in $files) { foreach($file in $files) {
if($file.Name.EndsWith('.OLD')) { continue; } if($file.Name.EndsWith('.OLD')) { continue; }
@@ -4159,7 +4159,7 @@ functions:
Write-Host \"Rename '$($file.FullName)' to '$newName'\"; Write-Host \"Rename '$($file.FullName)' to '$newName'\";
Move-Item -LiteralPath \"$($file.FullName)\" -Destination \"$newName\" -Force; Move-Item -LiteralPath \"$($file.FullName)\" -Destination \"$newName\" -Force;
} }
}; " };"
revertCode: revertCode:
PowerShell -Command " PowerShell -Command "
$package = (Get-AppxPackage -AllUsers '{{ $packageName }}'); $package = (Get-AppxPackage -AllUsers '{{ $packageName }}');
@@ -4169,15 +4169,15 @@ functions:
$directories = @($package.InstallLocation, \"$env:LOCALAPPDATA\Packages\$($package.PackageFamilyName)\"); $directories = @($package.InstallLocation, \"$env:LOCALAPPDATA\Packages\$($package.PackageFamilyName)\");
foreach($dir in $directories) { foreach($dir in $directories) {
if ( !$dir -Or !(Test-Path \"$dir\") ) { continue; } if ( !$dir -Or !(Test-Path \"$dir\") ) { continue; }
cmd /c takeown /f \"$dir\" /r /d y | Out-Null; cmd /c ('takeown /f \"' + $dir + '\" /r /d y 1> nul'); if($LASTEXITCODE) { throw 'Failed to take ownership'; }
cmd /c icacls \"$dir\" /grant administrators:F /t | Out-Null; cmd /c ('icacls \"' + $dir + '\" /grant administrators:F /t 1> nul'); if($LASTEXITCODE) { throw 'Failed to take ownership'; }
$files = Get-ChildItem -File -Path \"$dir\*.OLD\" -Recurse -Force; $files = Get-ChildItem -File -Path \"$dir\*.OLD\" -Recurse -Force;
foreach($file in $files) { foreach($file in $files) {
$newName = $file.FullName.Substring(0, $file.FullName.Length - 4); $newName = $file.FullName.Substring(0, $file.FullName.Length - 4);
Write-Host \"Rename '$($file.FullName)' to '$newName'\"; Write-Host \"Rename '$($file.FullName)' to '$newName'\";
Move-Item -LiteralPath \"$($file.FullName)\" -Destination \"$newName\" -Force; Move-Item -LiteralPath \"$($file.FullName)\" -Destination \"$newName\" -Force;
} }
}; " };"
- -
name: UninstallCapability name: UninstallCapability
parameters: [ capabilityName ] parameters: [ capabilityName ]