Better Functions
parent
d7d70aa329
commit
a3ee0728bd
|
@ -1,6 +1,6 @@
|
||||||
<# ARRAYS/VARIABLES #>
|
<# ARRAYS/VARIABLES #>
|
||||||
#App to Run (as SYSTEM)
|
#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"
|
#$RunSystem = "$PSScriptRoot\bins\MsiZap.exe"
|
||||||
#$RunSwitch = "tw! {GUID}"
|
#$RunSwitch = "tw! {GUID}"
|
||||||
$RunSystem = ""
|
$RunSystem = ""
|
||||||
|
@ -24,7 +24,9 @@ $WingetIDUninst = @("")
|
||||||
|
|
||||||
#Beginning of App Name string to Silently Uninstall (MSI/NSIS/INNO/EXE with defined silent uninstall in registry)
|
#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"!
|
#Multiple: "app1*","app2*", required wildcard (*) after; search is done with "-like"!
|
||||||
|
#Uninstall all versions if there exist several?
|
||||||
$AppUninst = @("")
|
$AppUninst = @("")
|
||||||
|
$AllVersions = $False
|
||||||
|
|
||||||
#Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2"
|
#Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2"
|
||||||
$Lnk = @("")
|
$Lnk = @("")
|
||||||
|
@ -97,7 +99,7 @@ if ($WingetIDUninst) {
|
||||||
Uninstall-WingetID $WingetIDUninst
|
Uninstall-WingetID $WingetIDUninst
|
||||||
}
|
}
|
||||||
if ($AppUninst) {
|
if ($AppUninst) {
|
||||||
Uninstall-ModsApp $AppUninst
|
Uninstall-ModsApp $AppUninst $AllVersions
|
||||||
}
|
}
|
||||||
if ($Lnk) {
|
if ($Lnk) {
|
||||||
Remove-ModsLnk $Lnk
|
Remove-ModsLnk $Lnk
|
||||||
|
|
|
@ -47,7 +47,7 @@ function Uninstall-WingetID ($WingetIDUninst) {
|
||||||
Return
|
Return
|
||||||
}
|
}
|
||||||
|
|
||||||
function Uninstall-ModsApp ($AppUninst) {
|
function Uninstall-ModsApp ($AppUninst, $AllVersions) {
|
||||||
foreach ($app in $AppUninst) {
|
foreach ($app in $AppUninst) {
|
||||||
$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
|
$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
|
||||||
foreach ($obj in $InstalledSoftware) {
|
foreach ($obj in $InstalledSoftware) {
|
||||||
|
@ -101,9 +101,11 @@ function Uninstall-ModsApp ($AppUninst) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$x64 = $true
|
$x64 = $true
|
||||||
|
if (!$AllVersions) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!$x64) {
|
if (!$x64) {
|
||||||
$InstalledSoftware = Get-ChildItem "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
|
$InstalledSoftware = Get-ChildItem "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
|
||||||
foreach ($obj in $InstalledSoftware) {
|
foreach ($obj in $InstalledSoftware) {
|
||||||
|
@ -156,11 +158,13 @@ function Uninstall-ModsApp ($AppUninst) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!$AllVersions) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Return
|
Return
|
||||||
}
|
}
|
||||||
function Remove-ModsLnk ($Lnk) {
|
function Remove-ModsLnk ($Lnk) {
|
||||||
|
@ -232,13 +236,21 @@ function Grant-ModsPath ($GrantPath) {
|
||||||
$NewAcl = Get-Acl -Path $path
|
$NewAcl = Get-Acl -Path $path
|
||||||
$identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11
|
$identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11
|
||||||
if ((Get-Item $path) -is [System.IO.DirectoryInfo]) {
|
if ((Get-Item $path) -is [System.IO.DirectoryInfo]) {
|
||||||
$fileSystemAccessRuleArgumentList = $identity, 'Modify', 'ContainerInherit, ObjectInherit', 'InheritOnly', 'Allow'
|
$fileSystemAccessRuleArgumentList = $identity, 'Modify', 'ContainerInherit, ObjectInherit', 'None', 'Allow'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$fileSystemAccessRuleArgumentList = $identity, 'Modify', 'Allow'
|
$fileSystemAccessRuleArgumentList = $identity, 'Modify', 'Allow'
|
||||||
}
|
}
|
||||||
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
|
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
|
||||||
$NewAcl.SetAccessRule($fileSystemAccessRule)
|
$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
|
Set-Acl -Path $path -AclObject $NewAcl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue