2022-05-22 22:26:00 +00:00
|
|
|
#Function to make actions post WAU update
|
|
|
|
|
|
|
|
function Invoke-PostUpdateActions {
|
2022-10-26 22:49:10 +00:00
|
|
|
|
2022-05-23 07:35:49 +00:00
|
|
|
#log
|
2022-05-22 22:26:00 +00:00
|
|
|
Write-Log "Running Post Update actions..." "yellow"
|
2022-06-03 19:54:09 +00:00
|
|
|
|
|
|
|
#Reset Winget Sources
|
2022-12-22 03:29:03 +00:00
|
|
|
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
|
2022-06-10 08:26:41 +00:00
|
|
|
if ($ResolveWingetPath) {
|
2022-06-03 19:54:09 +00:00
|
|
|
#If multiple version, pick last one
|
|
|
|
$WingetPath = $ResolveWingetPath[-1].Path
|
|
|
|
& $WingetPath source reset --force
|
2022-10-18 15:44:44 +00:00
|
|
|
|
|
|
|
#log
|
2022-06-03 19:54:09 +00:00
|
|
|
Write-Log "-> Winget sources reseted." "green"
|
|
|
|
}
|
2022-10-26 22:49:10 +00:00
|
|
|
|
2022-05-22 22:26:00 +00:00
|
|
|
#Create WAU Regkey if not present
|
|
|
|
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
|
|
|
|
if (!(test-path $regPath)) {
|
|
|
|
New-Item $regPath -Force
|
|
|
|
New-ItemProperty $regPath -Name DisplayName -Value "Winget-AutoUpdate (WAU)" -Force
|
2022-05-23 17:02:47 +00:00
|
|
|
New-ItemProperty $regPath -Name DisplayIcon -Value "C:\Windows\System32\shell32.dll,-16739" -Force
|
2022-05-22 22:26:00 +00:00
|
|
|
New-ItemProperty $regPath -Name NoModify -Value 1 -Force
|
|
|
|
New-ItemProperty $regPath -Name NoRepair -Value 1 -Force
|
|
|
|
New-ItemProperty $regPath -Name Publisher -Value "Romanitho" -Force
|
|
|
|
New-ItemProperty $regPath -Name URLInfoAbout -Value "https://github.com/Romanitho/Winget-AutoUpdate" -Force
|
|
|
|
New-ItemProperty $regPath -Name InstallLocation -Value $WorkingDir -Force
|
2022-05-25 09:56:39 +00:00
|
|
|
New-ItemProperty $regPath -Name UninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WorkingDir\WAU-Uninstall.ps1`"" -Force
|
|
|
|
New-ItemProperty $regPath -Name QuietUninstallString -Value "powershell.exe -noprofile -executionpolicy bypass -file `"$WorkingDir\WAU-Uninstall.ps1`"" -Force
|
2022-05-22 22:26:00 +00:00
|
|
|
New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force
|
2022-05-23 07:19:24 +00:00
|
|
|
|
|
|
|
#log
|
2022-05-23 07:35:49 +00:00
|
|
|
Write-Log "-> $regPath created." "green"
|
2022-05-22 22:26:00 +00:00
|
|
|
}
|
2022-06-15 11:20:42 +00:00
|
|
|
#Fix Notif where WAU_NotificationLevel is not set
|
|
|
|
$regNotif = Get-ItemProperty $regPath -Name WAU_NotificationLevel -ErrorAction SilentlyContinue
|
2022-06-15 11:23:32 +00:00
|
|
|
if (!$regNotif) {
|
2022-06-15 11:20:42 +00:00
|
|
|
New-ItemProperty $regPath -Name WAU_NotificationLevel -Value Full -Force
|
|
|
|
|
|
|
|
#log
|
|
|
|
Write-Log "-> Notification level setting was missing. Fixed with 'Full' option."
|
|
|
|
}
|
2022-10-26 22:49:10 +00:00
|
|
|
|
2023-01-13 02:33:00 +00:00
|
|
|
#Set WAU_MaxLogFiles/WAU_MaxLogSize if not set
|
|
|
|
$MaxLogFiles = Get-ItemProperty $regPath -Name WAU_MaxLogFiles -ErrorAction SilentlyContinue
|
|
|
|
if (!$MaxLogFiles) {
|
|
|
|
New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value 3 -PropertyType DWord -Force | Out-Null
|
|
|
|
New-ItemProperty $regPath -Name WAU_MaxLogSize -Value 1048576 -PropertyType DWord -Force | Out-Null
|
|
|
|
|
|
|
|
#log
|
|
|
|
Write-Log "-> MaxLogFiles/MaxLogSize setting was missing. Fixed with 3/1048576 (in bytes, default is 1048576 = 1 MB)."
|
|
|
|
}
|
|
|
|
|
2023-02-04 03:17:35 +00:00
|
|
|
#Security: Mods directory must be protected (Users could create scripts of their own - then they're run in System Context)!
|
2023-02-04 23:10:32 +00:00
|
|
|
#Check if Local Users have write rights in Mods directory or not
|
2023-02-04 03:17:35 +00:00
|
|
|
$WingetUpdatePath = Get-ItemProperty $regPath -Name InstallLocation -ErrorAction SilentlyContinue
|
|
|
|
$directory = Get-Item -Path "$WingetUpdatePath\mods"
|
|
|
|
$acl = Get-Acl -Path $directory.FullName
|
2023-02-04 23:10:32 +00:00
|
|
|
#Local Users - S-1-5-32-545
|
2023-02-04 03:17:35 +00:00
|
|
|
$userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-545")
|
2023-02-04 23:10:32 +00:00
|
|
|
#Translate SID to Locale Name
|
|
|
|
$ntAccount = $userSID.Translate([System.Security.Principal.NTAccount])
|
|
|
|
$userName = $ntAccount.Value
|
|
|
|
$userRights = [System.Security.AccessControl.FileSystemRights]"Write"
|
|
|
|
|
|
|
|
$hasWriteAccess = $False
|
|
|
|
|
|
|
|
foreach ($access in $acl.Access) {
|
|
|
|
if ($access.IdentityReference.Value -eq $userName -and $access.FileSystemRights -eq $userRights) {
|
|
|
|
$hasWriteAccess = $True
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($hasWriteAccess) {
|
|
|
|
#Disable inheritance
|
|
|
|
$acl.SetAccessRuleProtection($True, $True)
|
|
|
|
# Remove any existing rules
|
|
|
|
$acl.Access | ForEach-Object { $acl.RemoveAccessRule($_) }
|
|
|
|
#SYSTEM Full - S-1-5-18
|
|
|
|
$userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-18")
|
|
|
|
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID,"FullControl","ContainerInherit,ObjectInherit","None","Allow")
|
|
|
|
$acl.SetAccessRule($rule)
|
|
|
|
# Save the updated ACL
|
|
|
|
Set-Acl -Path $directory.FullName -AclObject $acl
|
2023-02-04 03:17:35 +00:00
|
|
|
|
2023-02-04 23:10:32 +00:00
|
|
|
#Administrators Full - S-1-5-32-544
|
|
|
|
$acl = Get-Acl -Path $directory.FullName
|
|
|
|
$userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544")
|
|
|
|
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID,"FullControl","ContainerInherit,ObjectInherit","None","Allow")
|
|
|
|
$acl.SetAccessRule($rule)
|
|
|
|
Set-Acl -Path $directory.FullName -AclObject $acl
|
|
|
|
|
|
|
|
#Local Users ReadAndExecute - S-1-5-32-545 S-1-5-11
|
|
|
|
$acl = Get-Acl -Path $directory.FullName
|
|
|
|
$userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-545")
|
|
|
|
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID, "ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow")
|
|
|
|
$acl.SetAccessRule($rule)
|
|
|
|
Set-Acl -Path $directory.FullName -AclObject $acl
|
|
|
|
|
|
|
|
#Authenticated Users ReadAndExecute - S-1-5-11
|
|
|
|
$acl = Get-Acl -Path $directory.FullName
|
|
|
|
$userSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-11")
|
|
|
|
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userSID, "ReadAndExecute","ContainerInherit,ObjectInherit","None","Allow")
|
|
|
|
$acl.SetAccessRule($rule)
|
|
|
|
Set-Acl -Path $directory.FullName -AclObject $acl
|
|
|
|
}
|
2023-02-04 00:08:38 +00:00
|
|
|
|
2022-05-22 22:26:00 +00:00
|
|
|
#Convert about.xml if exists (previous WAU versions) to reg
|
|
|
|
$WAUAboutPath = "$WorkingDir\config\about.xml"
|
|
|
|
if (test-path $WAUAboutPath) {
|
|
|
|
[xml]$About = Get-Content $WAUAboutPath -Encoding UTF8 -ErrorAction SilentlyContinue
|
|
|
|
New-ItemProperty $regPath -Name DisplayVersion -Value $About.app.version -Force
|
|
|
|
New-ItemProperty $regPath -Name VersionMajor -Value ([version]$About.app.version).Major -Force
|
|
|
|
New-ItemProperty $regPath -Name VersionMinor -Value ([version]$About.app.version).Minor -Force
|
|
|
|
|
|
|
|
#Remove file once converted
|
|
|
|
Remove-Item $WAUAboutPath -Force -Confirm:$false
|
2022-05-23 07:19:24 +00:00
|
|
|
|
|
|
|
#log
|
2022-05-23 07:35:49 +00:00
|
|
|
Write-Log "-> $WAUAboutPath converted." "green"
|
2022-05-22 22:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#Convert config.xml if exists (previous WAU versions) to reg
|
|
|
|
$WAUConfigPath = "$WorkingDir\config\config.xml"
|
|
|
|
if (test-path $WAUConfigPath) {
|
|
|
|
[xml]$Config = Get-Content $WAUConfigPath -Encoding UTF8 -ErrorAction SilentlyContinue
|
2022-06-10 08:26:41 +00:00
|
|
|
if ($Config.app.WAUautoupdate -eq "False") { New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value 1 -Force }
|
|
|
|
if ($Config.app.NotificationLevel) { New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $Config.app.NotificationLevel -Force }
|
|
|
|
if ($Config.app.UseWAUWhiteList -eq "True") { New-ItemProperty $regPath -Name WAU_UseWhiteList -Value 1 -PropertyType DWord -Force }
|
|
|
|
if ($Config.app.WAUprerelease -eq "True") { New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 1 -PropertyType DWord -Force }
|
2022-05-22 22:26:00 +00:00
|
|
|
|
|
|
|
#Remove file once converted
|
|
|
|
Remove-Item $WAUConfigPath -Force -Confirm:$false
|
2022-05-23 07:19:24 +00:00
|
|
|
|
|
|
|
#log
|
2022-05-23 07:35:49 +00:00
|
|
|
Write-Log "-> $WAUConfigPath converted." "green"
|
2022-05-22 22:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#Remove old functions
|
|
|
|
$FileNames = @(
|
|
|
|
"$WorkingDir\functions\Get-WAUConfig.ps1",
|
|
|
|
"$WorkingDir\functions\Get-WAUCurrentVersion.ps1",
|
|
|
|
"$WorkingDir\functions\Get-WAUUpdateStatus.ps1"
|
|
|
|
)
|
2022-06-10 08:26:41 +00:00
|
|
|
foreach ($FileName in $FileNames) {
|
2022-05-22 22:26:00 +00:00
|
|
|
if (Test-Path $FileName) {
|
|
|
|
Remove-Item $FileName -Force -Confirm:$false
|
2022-10-26 22:49:10 +00:00
|
|
|
|
2022-05-23 07:19:24 +00:00
|
|
|
#log
|
2022-05-23 07:35:49 +00:00
|
|
|
Write-Log "-> $FileName removed." "green"
|
2022-05-22 22:26:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#Reset WAU_UpdatePostActions Value
|
|
|
|
$WAUConfig | New-ItemProperty -Name WAU_PostUpdateActions -Value 0 -Force
|
|
|
|
|
2022-05-22 22:35:33 +00:00
|
|
|
#Get updated WAU Config
|
|
|
|
$Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
|
|
|
|
|
2022-05-23 07:35:49 +00:00
|
|
|
#log
|
|
|
|
Write-Log "Post Update actions finished" "green"
|
2022-10-26 22:49:10 +00:00
|
|
|
|
|
|
|
}
|