From 72e925fb6f908cd58fb50618f29726b3fb54a7f1 Mon Sep 17 00:00:00 2001 From: undergroundwires Date: Fri, 8 Jan 2021 01:08:09 +0100 Subject: [PATCH] improve uninstalling apps to show errors and exit if taking ownership fails #51 --- src/application/application.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/application/application.yaml b/src/application/application.yaml index 045796df..3b845766 100644 --- a/src/application/application.yaml +++ b/src/application/application.yaml @@ -4150,8 +4150,8 @@ functions: $directories = @($package.InstallLocation, \"$env:LOCALAPPDATA\Packages\$($package.PackageFamilyName)\"); foreach($dir in $directories) { if ( !$dir -Or !(Test-Path \"$dir\") ) { continue; } - cmd /c takeown /f \"$dir\" /r /d y | Out-Null; - cmd /c icacls \"$dir\" /grant administrators:F /t | 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 1> nul'); if($LASTEXITCODE) { throw 'Failed to take ownership'; } $files = Get-ChildItem -File -Path $dir -Recurse -Force; foreach($file in $files) { if($file.Name.EndsWith('.OLD')) { continue; } @@ -4159,7 +4159,7 @@ functions: Write-Host \"Rename '$($file.FullName)' to '$newName'\"; Move-Item -LiteralPath \"$($file.FullName)\" -Destination \"$newName\" -Force; } - }; " + };" revertCode: PowerShell -Command " $package = (Get-AppxPackage -AllUsers '{{ $packageName }}'); @@ -4169,15 +4169,15 @@ functions: $directories = @($package.InstallLocation, \"$env:LOCALAPPDATA\Packages\$($package.PackageFamilyName)\"); foreach($dir in $directories) { if ( !$dir -Or !(Test-Path \"$dir\") ) { continue; } - cmd /c takeown /f \"$dir\" /r /d y | Out-Null; - cmd /c icacls \"$dir\" /grant administrators:F /t | 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 1> nul'); if($LASTEXITCODE) { throw 'Failed to take ownership'; } $files = Get-ChildItem -File -Path \"$dir\*.OLD\" -Recurse -Force; foreach($file in $files) { $newName = $file.FullName.Substring(0, $file.FullName.Length - 4); Write-Host \"Rename '$($file.FullName)' to '$newName'\"; Move-Item -LiteralPath \"$($file.FullName)\" -Destination \"$newName\" -Force; } - }; " + };" - name: UninstallCapability parameters: [ capabilityName ]