From a3ee0728bd50c5cf26031728170647a515aea405 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Tue, 31 Oct 2023 02:53:12 +0100 Subject: [PATCH] Better Functions --- Winget-AutoUpdate/mods/_AppID-template.ps1 | 6 ++++-- Winget-AutoUpdate/mods/_Mods-Functions.ps1 | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index 72eb8df..8ace279 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -1,6 +1,6 @@ <# ARRAYS/VARIABLES #> #App to Run (as SYSTEM) -#$RunWait = $False if it shouldn't be waited for completion. For example: +#$RunWait = $False if it shouldn't be waited for completion. Example: #$RunSystem = "$PSScriptRoot\bins\MsiZap.exe" #$RunSwitch = "tw! {GUID}" $RunSystem = "" @@ -24,7 +24,9 @@ $WingetIDUninst = @("") #Beginning of App Name string to Silently Uninstall (MSI/NSIS/INNO/EXE with defined silent uninstall in registry) #Multiple: "app1*","app2*", required wildcard (*) after; search is done with "-like"! +#Uninstall all versions if there exist several? $AppUninst = @("") +$AllVersions = $False #Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2" $Lnk = @("") @@ -97,7 +99,7 @@ if ($WingetIDUninst) { Uninstall-WingetID $WingetIDUninst } if ($AppUninst) { - Uninstall-ModsApp $AppUninst + Uninstall-ModsApp $AppUninst $AllVersions } if ($Lnk) { Remove-ModsLnk $Lnk diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index a6550b3..eab4681 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -47,7 +47,7 @@ function Uninstall-WingetID ($WingetIDUninst) { Return } -function Uninstall-ModsApp ($AppUninst) { +function Uninstall-ModsApp ($AppUninst, $AllVersions) { foreach ($app in $AppUninst) { $InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall" foreach ($obj in $InstalledSoftware) { @@ -101,7 +101,9 @@ function Uninstall-ModsApp ($AppUninst) { } } $x64 = $true - break + if (!$AllVersions) { + break + } } } if (!$x64) { @@ -156,7 +158,9 @@ function Uninstall-ModsApp ($AppUninst) { } } } - break + if (!$AllVersions) { + break + } } } } @@ -232,13 +236,21 @@ function Grant-ModsPath ($GrantPath) { $NewAcl = Get-Acl -Path $path $identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11 if ((Get-Item $path) -is [System.IO.DirectoryInfo]) { - $fileSystemAccessRuleArgumentList = $identity, 'Modify', 'ContainerInherit, ObjectInherit', 'InheritOnly', 'Allow' + $fileSystemAccessRuleArgumentList = $identity, 'Modify', 'ContainerInherit, ObjectInherit', 'None', 'Allow' } else { $fileSystemAccessRuleArgumentList = $identity, 'Modify', 'Allow' } $fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList $NewAcl.SetAccessRule($fileSystemAccessRule) + + # Grant delete permissions to subfolders and files + $inheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit + $propagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly + $deleteAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $identity, 'Delete', $inheritanceFlag, $propagationFlag, 'Allow' + $NewAcl.AddAccessRule($deleteAccessRule) + + Set-Acl -Path $path -AclObject $NewAcl } }