Skip to content

Commit

Permalink
improve uninstalling apps to show errors and exit if taking ownership…
Browse files Browse the repository at this point in the history
… fails #51
  • Loading branch information
undergroundwires committed Jan 8, 2021
1 parent c299e95 commit 72e925f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/application/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4150,16 +4150,16 @@ 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; }
$newName = $file.FullName + '.OLD';
Write-Host \"Rename '$($file.FullName)' to '$newName'\";
Move-Item -LiteralPath \"$($file.FullName)\" -Destination \"$newName\" -Force;
}
}; "
};"
revertCode:
PowerShell -Command "
$package = (Get-AppxPackage -AllUsers '{{ $packageName }}');
Expand All @@ -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 ]
Expand Down

0 comments on commit 72e925f

Please sign in to comment.