diff --git a/Winget-AutoUpdate/mods/_AppID-template.ps1 b/Winget-AutoUpdate/mods/_AppID-template.ps1 index 5ceac13..7dda381 100644 --- a/Winget-AutoUpdate/mods/_AppID-template.ps1 +++ b/Winget-AutoUpdate/mods/_AppID-template.ps1 @@ -44,6 +44,9 @@ $DelFile = @("") $CopyFile = "" $CopyTo = "" +#Grant "Modify" for directory/file to "Authenticated Users" - multiple: "dir1","dir2" +$GrantPath = @("") + <# FUNCTIONS #> . $PSScriptRoot\_Mods-Functions.ps1 @@ -75,5 +78,8 @@ if ($DelFile) { if ($CopyFile -and $CopyTo) { Copy-ModsFile $CopyFile $CopyTo } +if ($GrantPath) { + Grant-ModsPath $GrantPath +} <# EXTRAS #> diff --git a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 index 705d344..c76eb95 100644 --- a/Winget-AutoUpdate/mods/_Mods-Functions.ps1 +++ b/Winget-AutoUpdate/mods/_Mods-Functions.ps1 @@ -192,3 +192,22 @@ function Copy-ModsFile ($CopyFile, $CopyTo) { Return } +function Grant-ModsPath ($GrantPath) { + foreach ($path in $GrantPath) + { + if (Test-Path "$path") { + $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' + } + else { + $fileSystemAccessRuleArgumentList = $identity, 'Modify', 'Allow' + } + $fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList + $NewAcl.SetAccessRule($fileSystemAccessRule) + Set-Acl -Path $path -AclObject $NewAcl + } + } + Return +}