From 840fad03da980effe6c07abf967c9f66692c2ece Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:07:47 +0200 Subject: [PATCH] Set ACL if log file exists --- Winget-AutoUpdate-Install.ps1 | 13 +++++++++++++ install.bat | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 990595b..ac9d00c 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -337,6 +337,19 @@ function Install-WingetAutoUpdate { New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value 1 -PropertyType DWord -Force | Out-Null } + #Set ACL for users on logfile + $LogFile = "$WingetUpdatePath\logs\updates.log" + if (test-path $LogFile){ + $NewAcl = Get-Acl -Path $LogFile + $identity = New-Object System.Security.Principal.SecurityIdentifier S-1-5-11 + $fileSystemRights = "Modify" + $type = "Allow" + $fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $type + $fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList + $NewAcl.SetAccessRule($fileSystemAccessRule) + Set-Acl -Path $LogFile -AclObject $NewAcl + } + #Create Shortcuts if ($StartMenuShortcut) { if (!(Test-Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)")) { diff --git a/install.bat b/install.bat index 6fcd9a2..3fd1e86 100644 --- a/install.bat +++ b/install.bat @@ -1,2 +1,5 @@ @echo off -powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-noprofile -executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -UpdatesAtLogon'" -Verb RunAs \ No newline at end of file + +SET arguments=-UpdatesAtLogon -UpdatesInterval Weekly -StartMenuShortcut + +powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-noprofile -executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" %arguments%'" -Verb RunAs \ No newline at end of file