improve uninstalling apps to show errors and exit if taking ownership fails #51
This commit is contained in:
@@ -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 ]
|
||||
|
||||
Reference in New Issue
Block a user