Better Functions

pull/459/head
KnifMelti 2023-10-31 02:53:12 +01:00
parent d7d70aa329
commit a3ee0728bd
2 changed files with 20 additions and 6 deletions

View File

@ -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

View File

@ -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,9 +101,11 @@ function Uninstall-ModsApp ($AppUninst) {
}
}
$x64 = $true
if (!$AllVersions) {
break
}
}
}
if (!$x64) {
$InstalledSoftware = Get-ChildItem "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ($obj in $InstalledSoftware) {
@ -156,11 +158,13 @@ function Uninstall-ModsApp ($AppUninst) {
}
}
}
if (!$AllVersions) {
break
}
}
}
}
}
Return
}
function Remove-ModsLnk ($Lnk) {
@ -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
}
}