Skip to content

Commit 274ceec

Browse files
authored
Merge pull request #418 from Romanitho/GPO-enhancement
Gpo enhancement / reworked
2 parents 0ff8d43 + 08a9a99 commit 274ceec

File tree

12 files changed

+169
-397
lines changed

12 files changed

+169
-397
lines changed

.github/workflows/WAU-AutoCreatePreVersion.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ jobs:
8282

8383
- name: Build project
8484
run: |
85-
zip -r WAU Winget-AutoUpdate/*
86-
zip -r WAU Winget-AutoUpdate-Install.ps1
87-
zip -r WAU excluded_apps.txt
88-
zip -r WAU install.bat
89-
zip -r WAU uninstall.bat
85+
zip -r WAU.zip Winget-AutoUpdate
86+
zip WAU.zip Winget-AutoUpdate-Install.ps1
87+
zip WAU.zip excluded_apps.txt
88+
zip WAU.zip install.bat
89+
zip WAU.zip uninstall.bat
90+
cd Policies
91+
zip -r ../WAU_ADMX.zip *
92+
cd ..
9093
9194
- name: Create release
9295
uses: "ncipollo/release-action@v1"
@@ -96,7 +99,7 @@ jobs:
9699
prerelease: true
97100
generateReleaseNotes: true
98101
name: "v${{ steps.versioning.outputs.version }} [Nightly Build]"
99-
artifacts: "WAU.zip"
102+
artifacts: "WAU.zip,WAU_ADMX.zip"
100103

101104
- name: URL to release
102105
run: echo "Release -> ${{ steps.release.outputs.html_url }}"

.github/workflows/WAU-CreateNewVersion.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ jobs:
5555

5656
- name: Build project
5757
run: |
58-
zip -r WAU Winget-AutoUpdate/*
59-
zip -r WAU Winget-AutoUpdate-Install.ps1
60-
zip -r WAU excluded_apps.txt
61-
zip -r WAU install.bat
62-
zip -r WAU uninstall.bat
58+
zip -r WAU.zip Winget-AutoUpdate
59+
zip WAU.zip Winget-AutoUpdate-Install.ps1
60+
zip WAU.zip excluded_apps.txt
61+
zip WAU.zip install.bat
62+
zip WAU.zip uninstall.bat
63+
cd Policies
64+
zip -r ../WAU_ADMX.zip *
65+
cd ..
6366
6467
- name: Create release
6568
uses: "ncipollo/release-action@v1"
@@ -68,4 +71,4 @@ jobs:
6871
prerelease: ${{ github.event.inputs.pre-release }}
6972
generateReleaseNotes: true
7073
name: "v${{ steps.versioning.outputs.version }}"
71-
artifacts: "WAU.zip"
74+
artifacts: "WAU.zip,WAU_ADMX.zip"
File renamed without changes.
File renamed without changes.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ Remove scheduled tasks and scripts.
172172
See https://github.com/Romanitho/Winget-AutoUpdate/discussions/88
173173

174174
## Custom script (Mods for WAU)
175-
**Mods for WAU** allows you to craft a script to do whatever you like via `_WAU-mods.ps1` in the **mods** folder.
176-
This script executes **if the network is active/any version of Winget is installed/WAU is running as SYSTEM**.
175+
**Mods for WAU** allows you to craft a script to do whatever you like via `_WAU-mods.ps1` in the **mods** folder.<br>
176+
This script executes **if the network is active/any version of Winget is installed/WAU is running as SYSTEM**.<br>
177177
If **ExitCode** is **1** from `_WAU-mods.ps1` then **Re-run WAU**.
178178
## Custom scripts (Mods feature for Apps)
179179
From version 1.8.0, the Mods feature allows you to run additional scripts when upgrading or installing an app.
@@ -206,7 +206,7 @@ This will use the **content** of the text file as a native **winget --override**
206206
In an enterprise environment it's crucial that different groups can have different settings in applications etc. or to implement other mandatory settings, i.e for security/management reasons.<br>
207207
**WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin**).<br>
208208
With the use of **ADML/ADMX** files you can manage every **WAU** setting from within **GPO**.<br>
209-
They will be detected/evaluated during the next run of **WAU** (taking effect before any actions).<br>
209+
They will be detected/evaluated on a daily basis.<br>
210210
The **GPO ADMX/ADML** validated with: [Windows 10 - Validate ADMX for Ingestion](https://developer.vmware.com/samples/7115/windows-10---validate-admx-for-ingestion)<br>
211211
Read more in the `README.md` under the directory **Policies**.
212212

Winget-AutoUpdate-Install.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function Install-WinGet {
249249
}
250250
Remove-Item -Path $VCLibsFile -Force
251251
}
252-
252+
253253
#Download WinGet MSIXBundle
254254
Write-Host "-> Downloading WinGet MSIXBundle for App Installer..."
255255
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$WinGetAvailableVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
@@ -401,6 +401,15 @@ function Install-WingetAutoUpdate {
401401
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
402402
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
403403

404+
# Settings for the GPO scheduled task
405+
$taskAction = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\WAU-Policies.ps1`""
406+
$tasktrigger = New-ScheduledTaskTrigger -Daily -At 6am
407+
$taskUserPrincipal = New-ScheduledTaskPrincipal -UserId S-1-5-18 -RunLevel Highest
408+
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 00:05:00
409+
# Set up the task, and register it
410+
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTrigger
411+
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Policies' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
412+
404413
#Set task readable/runnable for all users
405414
$scheduler = New-Object -ComObject "Schedule.Service"
406415
$scheduler.Connect()
@@ -433,6 +442,7 @@ function Install-WingetAutoUpdate {
433442
New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value $MaxLogFiles -PropertyType DWord -Force | Out-Null
434443
New-ItemProperty $regPath -Name WAU_MaxLogSize -Value $MaxLogSize -PropertyType DWord -Force | Out-Null
435444
New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value $UpdatesAtTime -Force | Out-Null
445+
New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value $UpdatesInterval -Force | Out-Null
436446
if ($UpdatesAtLogon) {
437447
New-ItemProperty $regPath -Name WAU_UpdatesAtLogon -Value 1 -PropertyType DWord -Force | Out-Null
438448
}
@@ -540,6 +550,7 @@ function Uninstall-WingetAutoUpdate {
540550
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
541551
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
542552
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
553+
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Policies" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
543554
& reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null
544555
& reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null
545556

Winget-AutoUpdate/WAU-Policies.ps1

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<#
2+
.SYNOPSIS
3+
Handle GPO/Polices
4+
5+
.DESCRIPTION
6+
Daily update settings from policies
7+
#>
8+
9+
#Import functions
10+
. "$PSScriptRoot\functions\Get-WAUConfig.ps1"
11+
. "$PSScriptRoot\functions\Add-Shortcut.ps1"
12+
13+
#Check if GPO Management is enabled
14+
$ActivateGPOManagement = Get-ItemPropertyValue "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "WAU_ActivateGPOManagement" -ErrorAction SilentlyContinue
15+
if ($ActivateGPOManagement -eq 1) {
16+
#Add (or update) tag to activate WAU-Policies Management
17+
New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 1 -Force | Out-Null
18+
}
19+
20+
#Get WAU settings
21+
$WAUConfig = Get-WAUConfig
22+
23+
#Check if GPO got applied from Get-WAUConfig (tag)
24+
if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
25+
26+
#Log init
27+
$GPOLogFile = "$($WAUConfig.InstallLocation)\logs\LatestAppliedSettings.txt"
28+
Set-Content -Path $GPOLogFile -Value "### POLICY CYCLE - $(Get-Date) ###`n"
29+
30+
#Reset WAU_RunGPOManagement if not GPO managed anymore (This is used to run this job one last time and reset initial settings)
31+
if ($($WAUConfig.WAU_ActivateGPOManagement -eq 1)) {
32+
Add-Content -Path $GPOLogFile -Value "GPO Management Enabled. Policies updated."
33+
}
34+
else {
35+
New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 0 -Force | Out-Null
36+
$WAUConfig.WAU_RunGPOManagement = 0
37+
Add-Content -Path $GPOLogFile -Value "GPO Management Disabled. Policies removed."
38+
}
39+
40+
#Get Winget-AutoUpdate scheduled task
41+
$WAUTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate' -ErrorAction SilentlyContinue
42+
43+
#Update 'Winget-AutoUpdate' scheduled task settings
44+
$taskTriggers = @()
45+
if ($WAUConfig.WAU_UpdatesAtLogon -eq 1) {
46+
$tasktriggers += New-ScheduledTaskTrigger -AtLogOn
47+
}
48+
if ($WAUConfig.WAU_UpdatesInterval -eq "Daily") {
49+
$tasktriggers += New-ScheduledTaskTrigger -Daily -At $WAUConfig.WAU_UpdatesAtTime
50+
}
51+
elseif ($WAUConfig.WAU_UpdatesInterval -eq "BiDaily") {
52+
$tasktriggers += New-ScheduledTaskTrigger -Daily -At $WAUConfig.WAU_UpdatesAtTime -DaysInterval 2
53+
}
54+
elseif ($WAUConfig.WAU_UpdatesInterval -eq "Weekly") {
55+
$tasktriggers += New-ScheduledTaskTrigger -Weekly -At $WAUConfig.WAU_UpdatesAtTime -DaysOfWeek 2
56+
}
57+
elseif ($WAUConfig.WAU_UpdatesInterval -eq "BiWeekly") {
58+
$tasktriggers += New-ScheduledTaskTrigger -Weekly -At $WAUConfig.WAU_UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 2
59+
}
60+
elseif ($WAUConfig.WAU_UpdatesInterval -eq "Monthly") {
61+
$tasktriggers += New-ScheduledTaskTrigger -Weekly -At $WAUConfig.WAU_UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 4
62+
}
63+
#If trigger(s) set
64+
if ($taskTriggers) {
65+
#Edit scheduled task
66+
Set-ScheduledTask -TaskPath $WAUTask.TaskPath -TaskName $WAUTask.TaskName -Trigger $taskTriggers | Out-Null
67+
}
68+
#If not, remove trigger(s)
69+
else {
70+
#Remove by setting past due date
71+
$tasktriggers = New-ScheduledTaskTrigger -Once -At "01/01/1970"
72+
Set-ScheduledTask -TaskPath $WAUTask.TaskPath -TaskName $WAUTask.TaskName -Trigger $taskTriggers | Out-Null
73+
}
74+
75+
#Update Desktop shortcut
76+
$DesktopShortcut = "${env:Public}\Desktop\WAU - Check for updated Apps.lnk"
77+
if (($WAUConfig.WAU_DesktopShortcut -eq 1) -and !(Test-Path $DesktopShortcut)) {
78+
Add-Shortcut "wscript.exe" $DesktopShortcut "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..."
79+
}
80+
elseif ($WAUConfig.WAU_DesktopShortcut -ne 1) {
81+
Remove-Item -Path $DesktopShortcut -Force -ErrorAction SilentlyContinue | Out-Null
82+
}
83+
84+
#Update Start Menu shortcuts
85+
$StartMenuShortcut = "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)"
86+
if (($WAUConfig.WAU_StartMenuShortcut -eq 1) -and !(Test-Path $StartMenuShortcut)) {
87+
New-Item -ItemType Directory -Force -Path $StartMenuShortcut | Out-Null
88+
Add-Shortcut "wscript.exe" "$StartMenuShortcut\WAU - Check for updated Apps.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..."
89+
Add-Shortcut "wscript.exe" "$StartMenuShortcut\WAU - Open logs.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Logs`"" "${env:SystemRoot}\System32\shell32.dll,-16763" "Open existing WAU logs..."
90+
Add-Shortcut "wscript.exe" "$StartMenuShortcut\WAU - Web Help.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Help`"" "${env:SystemRoot}\System32\shell32.dll,-24" "Help for WAU..."
91+
}
92+
elseif ($WAUConfig.WAU_StartMenuShortcut -ne 1) {
93+
Remove-Item -Path $StartMenuShortcut -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
94+
}
95+
96+
#Log latest applied config
97+
Add-Content -Path $GPOLogFile -Value "`nLatest applied settings:"
98+
$WAUConfig.PSObject.Properties | Where-Object { $_.Name -like "WAU_*" } | Select-Object Name, Value | Out-File -Encoding default -FilePath $GPOLogFile -Append
99+
}
100+
101+
Exit 0

Winget-AutoUpdate/WAU-Uninstall.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ try {
5050
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
5151
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
5252
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
53+
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Policies" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
5354
& reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null
5455
& reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null
5556
if (Test-Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate") {

Winget-AutoUpdate/Winget-Upgrade.ps1

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,16 @@ $Script:IsSystem = [System.Security.Principal.WindowsIdentity]::GetCurrent().IsS
1414
#Run log initialisation function
1515
Start-Init
1616

17-
#Get WAU Configurations
18-
$Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
17+
#Get settings and Domain/Local Policies (GPO) if activated.
18+
$WAUConfig = Get-WAUConfig
19+
if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {
20+
Write-ToLog "WAU Policies management Enabled."
21+
}
1922

2023
#Log running context and more...
2124
if ($IsSystem) {
2225
Write-ToLog "Running in System context"
2326

24-
#Get and set Domain/Local Policies (GPO)
25-
$ActivateGPOManagement, $ChangedSettings = Get-Policies
26-
if ($ActivateGPOManagement) {
27-
Write-ToLog "Activated WAU GPO Management detected, comparing..."
28-
if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0) {
29-
Write-ToLog "Changed settings detected and applied" "Yellow"
30-
}
31-
else {
32-
Write-ToLog "No Changed settings detected" "Yellow"
33-
}
34-
}
35-
3627
# Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files.
3728
$MaxLogFiles = $WAUConfig.WAU_MaxLogFiles
3829
if ($null -eq $MaxLogFiles) {
@@ -315,7 +306,7 @@ if (Test-Network) {
315306
$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue
316307
if (!$UserContextTask) {
317308
#Create the scheduled task in User context
318-
$taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-upgrade.ps1`"`""
309+
$taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\winget-upgrade.ps1`"`""
319310
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
320311
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00
321312
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings

0 commit comments

Comments
 (0)