diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 1569fe3..6b39233 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -25,6 +25,9 @@ Use White List instead of Black List. This setting will not create the "exclude_ .PARAMETER Uninstall Remove scheduled tasks and scripts. +.PARAMETER NotificationLevel +Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). + .EXAMPLE .\winget-install-and-update.ps1 -Silent -DoNotUpdate @@ -41,6 +44,7 @@ param( [Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false, [Parameter(Mandatory=$False)] [Switch] $Uninstall = $false, [Parameter(Mandatory=$False)] [Switch] $UseWhiteList = $false + [Parameter(Mandatory=$False)] [ValidateSet("Full","SuccessOnly","None")] [Switch] $NotificationLevel = "Full" ) @@ -191,6 +195,7 @@ function Install-WingetAutoUpdate{ $(!($DisableWAUAutoUpdate)) False $UseWhiteList + $NotificationLevel "@ $ConfigXML.Save("$WingetUpdatePath\config\config.xml") diff --git a/Winget-AutoUpdate/functions/Get-NotifLocale.ps1 b/Winget-AutoUpdate/functions/Get-NotifLocale.ps1 index fda334c..4fe9038 100644 --- a/Winget-AutoUpdate/functions/Get-NotifLocale.ps1 +++ b/Winget-AutoUpdate/functions/Get-NotifLocale.ps1 @@ -20,7 +20,7 @@ Function Get-NotifLocale { } #Get locale XML file content - Write-Log "Notification Langugage : $LocaleDisplayName" "Cyan" + Write-Log "Notification Level: $NotificationLevel. Notification Language: $LocaleDisplayName" "Cyan" [xml]$Script:NotifLocale = Get-Content $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue } \ No newline at end of file diff --git a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 index 6670572..8e2cc1b 100644 --- a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 +++ b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 @@ -2,16 +2,24 @@ function Get-WAUConfig{ + #Get config file [xml]$WAUConfig = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue #Check if WAU is configured for Black or White List if ($true -eq [System.Convert]::ToBoolean($WAUConfig.app.UseWAUWhiteList)){ - Write-Log "WAU uses White List config" $Script:UseWhiteList = $true } else{ - Write-Log "WAU uses Black List config" $Script:UseWhiteList = $false } + + #Get Notification Level + if ($WAUConfig.app.NotificationLevel){ + $Script:NotificationLevel = $WAUConfig.app.NotificationLevel + } + else{ + #Default: Full + $Script:NotificationLevel = $full + } } diff --git a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 b/Winget-AutoUpdate/functions/Start-NotifTask.ps1 index 941a4cc..4b68c8c 100644 --- a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 +++ b/Winget-AutoUpdate/functions/Start-NotifTask.ps1 @@ -2,8 +2,10 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) { - #Add XML variables - [xml]$ToastTemplate = @" + if (($NotificationLevel -eq "Full") -or ($NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success")) { + + #Add XML variables + [xml]$ToastTemplate = @" @@ -16,45 +18,47 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) { "@ - #Check if running account is system or interactive logon - $currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4") - - #if not "Interactive" user, run as system - if ($currentPrincipal -eq $false){ - - #Save XML to File - $ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\" - if (!(Test-Path $ToastTemplateLocation)){ - New-Item -ItemType Directory -Force -Path $ToastTemplateLocation - } - $ToastTemplate.Save("$ToastTemplateLocation\config\notif.xml") - - #Run Notify scheduled task to notify conneted users - Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue - - } - #else, run as connected user - else{ - - #Load Assemblies - [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null - [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null - - #Prepare XML - $ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New() - $ToastXml.LoadXml($ToastTemplate.OuterXml) - - #Specify Launcher App ID - $LauncherID = "Windows.SystemToast.Winget.Notification" + #Check if running account is system or interactive logon + $currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4") - #Prepare and Create Toast - $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXml) - $ToastMessage.Tag = $ToastTemplate.toast.tag - [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage) + #if not "Interactive" user, run as system + if ($currentPrincipal -eq $false){ + + #Save XML to File + $ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\" + if (!(Test-Path $ToastTemplateLocation)){ + New-Item -ItemType Directory -Force -Path $ToastTemplateLocation + } + $ToastTemplate.Save("$ToastTemplateLocation\config\notif.xml") + + #Run Notify scheduled task to notify conneted users + Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue + + } + #else, run as connected user + else{ + + #Load Assemblies + [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null + [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null + + #Prepare XML + $ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New() + $ToastXml.LoadXml($ToastTemplate.OuterXml) + + #Specify Launcher App ID + $LauncherID = "Windows.SystemToast.Winget.Notification" + + #Prepare and Create Toast + $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXml) + $ToastMessage.Tag = $ToastTemplate.toast.tag + [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage) + + } + + #Wait for notification to display + Start-Sleep 3 } - #Wait for notification to display - Start-Sleep 3 - } \ No newline at end of file diff --git a/Winget-AutoUpdate/winget-upgrade.ps1 b/Winget-AutoUpdate/winget-upgrade.ps1 index eed297f..db24ffc 100644 --- a/Winget-AutoUpdate/winget-upgrade.ps1 +++ b/Winget-AutoUpdate/winget-upgrade.ps1 @@ -11,6 +11,9 @@ Get-ChildItem "$WorkingDir\functions" | ForEach-Object {. $_.FullName} #Run log initialisation function Start-Init +#Get WAU Configurations +Get-WAUConfig + #Get Notif Locale function Get-NotifLocale @@ -40,11 +43,12 @@ if (Test-Network){ } #Get White or Black list - Get-WAUConfig if ($UseWhiteList){ + Write-Log "WAU uses White List config" $toUpdate = Get-IncludedApps } else{ + Write-Log "WAU uses Black List config" $toSkip = Get-ExcludedApps } diff --git a/install.bat b/install.bat index 1989d70..54891cf 100644 --- a/install.bat +++ b/install.bat @@ -1,2 +1,2 @@ @echo off -powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" '" -Verb RunAs +powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-noprofile -executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" '" -Verb RunAs diff --git a/uninstall.bat b/uninstall.bat index 2ffacc9..6667d2e 100644 --- a/uninstall.bat +++ b/uninstall.bat @@ -1,2 +1,2 @@ @echo off -powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -Uninstall'" -Verb RunAs \ No newline at end of file +powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-noprofile -executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -Uninstall'" -Verb RunAs \ No newline at end of file