diff --git a/Winget-AutoUpdate/User-Run.ps1 b/Winget-AutoUpdate/User-Run.ps1 index a3b753c..199e1f7 100644 --- a/Winget-AutoUpdate/User-Run.ps1 +++ b/Winget-AutoUpdate/User-Run.ps1 @@ -21,8 +21,7 @@ https://github.com/Romanitho/Winget-AutoUpdate param( [Parameter(Mandatory = $False)] [Switch] $Logs = $false, [Parameter(Mandatory = $False)] [Switch] $Help = $false, - [Parameter(Mandatory = $False)] [Switch] $NotifApprovedAsSystem = $false, - [Parameter(Mandatory = $False)] [Switch] $NotifApprovedAsUser = $false + [Parameter(Mandatory = $False)] [String] $NotifApproved, ) function Test-WAUisRunning { @@ -61,17 +60,16 @@ if ($Logs) { elseif ($Help) { Start-Process "https://github.com/Romanitho/Winget-AutoUpdate" } -elseif ($NotifApprovedAsUser){ +elseif ($NotifApproved){ #Create tag if user approve notif for requested updates $WAUNotifApprovedPath = "$WingetUpdatePath\config\NotifApproved.txt" New-Item $WAUNotifApprovedPath -Force - Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue -} -elseif ($NotifApprovedAsSystem){ - #Create tag if user approve notif for requested updates - $WAUNotifApprovedPath = "$WingetUpdatePath\config\NotifApproved.txt" - New-Item $WAUNotifApprovedPath -Force - Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue + if ($NotifApproved -like "*system"){ + Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction Stop | Start-ScheduledTask -ErrorAction Stop + } + else{ + Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction Stop | Start-ScheduledTask -ErrorAction Stop + } } else { try { diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index 3b2e8e0..81e35cb 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -236,6 +236,29 @@ if (Test-Network) { $Log | out-file -filepath $LogFile -Append } + #Ask user to approve, if configured + if ($WAUConfig.WAU_UserApproval -eq 1){ + Write-Log "User Approval feature enabled." + + #Check for approved tag + $WAUNotifApproved = "$WorkingDir/Config/NotifApproved.txt" + if (Test-Path $WAUNotifApproved) { + Write-Log "-> User approved notification." + Remove-Item $WAUNotifApproved -Force -Confirm:$false + } + else { + $UserApprovalReturn = Invoke-UserApproval $outdated + if ($UserApprovalReturn -eq 0){ + Write-Log "-> User approval requested. Waiting for user to approve available updates... Closing for now." + #Closing job, waiting for user approval + Exit 0 + } + else{ + Write-log "-> No update to request to user." + } + } + } + #Count good update installations $Script:InstallOK = 0 diff --git a/Winget-AutoUpdate/functions/Invoke-UserApproval.ps1 b/Winget-AutoUpdate/functions/Invoke-UserApproval.ps1 index ee9f986..905324d 100644 --- a/Winget-AutoUpdate/functions/Invoke-UserApproval.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-UserApproval.ps1 @@ -3,19 +3,20 @@ function Invoke-UserApproval ($outdated){ #Create / Update WAU Class for notification action - $WAUClass = "HKLM:\Software\Classes\WAU" - $WAUClassCmd = "$WAUClass\shell\open\command" - if ($IsSystem){ - $WAUClassRun = "Wscript.exe ""$WingetUpdatePath\Invisible.vbs"" ""powershell.exe -NoProfile -ExecutionPolicy Bypass -File '$WingetUpdatePath\User-Run.ps1' -NotifApprovedAsSystem" + if ($IsSystem) { + $WAUClass = "HKLM:\Software\Classes\WAU" + $WAUClassCmd = "$WAUClass\shell\open\command" + $WAUClassRun = "Wscript.exe ""$WingetUpdatePath\Invisible.vbs"" ""powershell.exe -NoProfile -ExecutionPolicy Bypass -Command & '$WingetUpdatePath\User-Run.ps1' -NotifApproved %1""" + New-Item $WAUClassCmd -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath $WAUClass -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath $WAUClass -Name '(default)' -Value "URL:$($ActionType)" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath $WAUClass -Name 'EditFlags' -Value '2162688' -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath $WAUClassCmd -Name '(default)' -Value $WAUClassRun -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + $Button1Action = "wau:system" } else{ - $WAUClassRun = "Wscript.exe ""$WingetUpdatePath\Invisible.vbs"" ""powershell.exe -NoProfile -ExecutionPolicy Bypass -File '$WingetUpdatePath\User-Run.ps1' -NotifApprovedAsUser" + $Button1Action = "wau:user" } - New-Item $WAUClassCmd -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath $WAUClass -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath $WAUClass -Name '(default)' -Value "URL:$($ActionType)" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath $WAUClass -Name 'EditFlags' -Value '2162688' -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath $WAUClassCmd -Name '(default)' -Value $WAUClassRun -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null $OutdatedApps = @() #If White List @@ -40,7 +41,7 @@ function Invoke-UserApproval ($outdated){ $body = $OutdatedApps | Out-String if ($body) { #Ask user to update apps - Start-NotifTask -Title "New available updates" -Message "Do you want to update these apps ?" -Body $body -ButtonDismiss -Button1Text "Yes" -Button1Action "wau:1" -MessageType "info" + Start-NotifTask -Title "New available updates" -Message "Do you want to update these apps ?" -Body $body -ButtonDismiss -Button1Text "Yes" -Button1Action $Button1Action -MessageType "info" Return 0 } else {