1st approach
parent
833339ab84
commit
65f97c8a02
|
@ -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
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
else {
|
||||
try {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -3,19 +3,20 @@
|
|||
function Invoke-UserApproval ($outdated){
|
||||
|
||||
#Create / Update WAU Class for notification action
|
||||
if ($IsSystem) {
|
||||
$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"
|
||||
}
|
||||
else{
|
||||
$WAUClassRun = "Wscript.exe ""$WingetUpdatePath\Invisible.vbs"" ""powershell.exe -NoProfile -ExecutionPolicy Bypass -File '$WingetUpdatePath\User-Run.ps1' -NotifApprovedAsUser"
|
||||
}
|
||||
$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{
|
||||
$Button1Action = "wau:user"
|
||||
}
|
||||
|
||||
$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 {
|
||||
|
|
Loading…
Reference in New Issue