From e40d5f441aa1083d208d5408bd4767888b592c63 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Sun, 24 Apr 2022 10:51:51 +0200
Subject: [PATCH 1/6] Added Notification Level Feature
---
Winget-AutoUpdate-Install.ps1 | 5 ++
.../functions/Get-NotifLocale.ps1 | 2 +-
Winget-AutoUpdate/functions/Get-WAUConfig.ps1 | 12 ++-
.../functions/Start-NotifTask.ps1 | 82 ++++++++++---------
Winget-AutoUpdate/winget-upgrade.ps1 | 6 +-
install.bat | 2 +-
uninstall.bat | 2 +-
7 files changed, 66 insertions(+), 45 deletions(-)
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
From 24a8343ff36dbb0ebbfd2dd9d4317aba941a94bf Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Sun, 24 Apr 2022 10:56:29 +0200
Subject: [PATCH 2/6] v1.9.0
---
Winget-AutoUpdate/config/about.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Winget-AutoUpdate/config/about.xml b/Winget-AutoUpdate/config/about.xml
index 1e0a6f9..a0f8929 100644
--- a/Winget-AutoUpdate/config/about.xml
+++ b/Winget-AutoUpdate/config/about.xml
@@ -1,7 +1,7 @@
Winget-AutoUpdate (WAU)
- 1.8.0
+ 1.9.0
Romanitho
https://github.com/Romanitho/Winget-AutoUpdate
From 20cd9a4312fc4289e0f49a13607aa3c10240f8c8 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:02:39 +0200
Subject: [PATCH 3/6] missing comma
---
Winget-AutoUpdate-Install.ps1 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1
index 6b39233..8d39796 100644
--- a/Winget-AutoUpdate-Install.ps1
+++ b/Winget-AutoUpdate-Install.ps1
@@ -43,7 +43,7 @@ param(
[Parameter(Mandatory=$False)] [Switch] $DoNotUpdate = $false,
[Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false,
[Parameter(Mandatory=$False)] [Switch] $Uninstall = $false,
- [Parameter(Mandatory=$False)] [Switch] $UseWhiteList = $false
+ [Parameter(Mandatory=$False)] [Switch] $UseWhiteList = $false,
[Parameter(Mandatory=$False)] [ValidateSet("Full","SuccessOnly","None")] [Switch] $NotificationLevel = "Full"
)
From 7c746ad7acc8b26f1f1ecd6786c57f63dc29bc10 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Sun, 24 Apr 2022 11:05:16 +0200
Subject: [PATCH 4/6] Wrong type
---
Winget-AutoUpdate-Install.ps1 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1
index 8d39796..50cacd8 100644
--- a/Winget-AutoUpdate-Install.ps1
+++ b/Winget-AutoUpdate-Install.ps1
@@ -44,7 +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"
+ [Parameter(Mandatory=$False)] [ValidateSet("Full","SuccessOnly","None")] [String] $NotificationLevel = "Full"
)
From c0666547ff60f9efe3fb9e856351960cf43c8a26 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Sun, 24 Apr 2022 12:04:14 +0200
Subject: [PATCH 5/6] added documentation
---
README.md | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
index ad68d66..0131fc1 100644
--- a/README.md
+++ b/README.md
@@ -14,17 +14,25 @@ You can exclude apps from update job (for instance, apps you want to keep at a s
Add (or remove) the apps' ID you want to disable autoupdate to 'excluded_apps.txt'. (File must be placed in scripts' installation folder, or re-run install.bat).
- #### Or White List
From 1.7.0 version, you can update only pre-selected apps. To do so, create an "included_apps.txt" with the apps' ID of the apps you want to auto-update and run the `Winget-AutoUpdate-Install.ps1` with `-UseWhiteList` parameter. Related post: https://github.com/Romanitho/Winget-AutoUpdate/issues/36
-### Default install location
-By default, scripts and components will be placed in ProgramData location (inside a Winget-AutoUpdate folder). You can change this with script argument.
+
+### Notification Level
+From version 1.9.0, you can choose which notification will be displayed: Full, Success only or none. Use `-NotificationLevel` parameter when you run `Winget-AutoUpdate-Install.ps1`
+
### Notification language
You can easily translate toast notifications by creating your locale xml config file (and share it with us :) ).
+
+### Default install location
+By default, scripts and components will be placed in ProgramData location (inside a Winget-AutoUpdate folder). You can change this with script argument (Not Recommended).
+
### When does the script run?
Scheduled task is set to run:
- At user logon
- At 6AM Everyday (with the -StartWhenAvailable option to be sure it is run at least once a day)
This way, even without connected user, powered on computers get updated anyway.
+
### Log location
You can find logs in install location, in log folder.
+
### "Unknown" App version
As explained in this [post](https://github.com/microsoft/winget-cli/issues/1255), Winget cannot detect the current version of some installed apps. We decided to skip managing these apps with WAU to avoid retries each time WAU runs:
@@ -58,21 +66,22 @@ Disable Winget-AutoUpdate update checking. By default, WAU auto updates if new v
**-UseWhiteList**
Use White List instead of Black List. This setting will not create the "exclude_apps.txt" but "include_apps.txt"
+**-NotificationLevel**
+Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup).
+
**-Uninstall**
Remove scheduled tasks and scripts.
## Custom scripts (Mods feature)
-
-The Mods feature allows you to run an additional script when installing or upgrading an app.
-Just put the script with the App ID followed by the "-install" or "-upgrade" suffix to be considered.
-`AppID-install.ps1` and/or `AppID-upgrade.ps1` (if it differs, otherwise the "-install" mod will be used for upgrade)
+From version 1.8.0, The Mods feature allows you to run an additional script when installing or upgrading an app.
+Just put the script with the App ID followed by the "-install" or "-upgrade" suffix to be considered.
+Call `AppID-install.ps1` and/or `AppID-upgrade.ps1` (if it differs, otherwise the "-install" mod will be used for upgrade)
and put this in the Mods directory
> Example:
-> If you want to run a script just after installing ".NET Desktop Runtime 6", call your script like this:
-> `Microsoft.dotnetRuntime.6-x64-install.ps1`
-
-In the case of ".NET Desktop Runtime 6" it spawns a new process and this we will have to wait for completion of before moving on to checking if the installation/upgrade suceeded or not. - (this seems to be handled in Winget Version: v1.3.0-preview)
+> If you want to run a script that remove desktop shortcut just after installing "Google Chrome", prepare a powershell script that remove desktop shortcut, call your script like this:
+> `Google.Chrome-install.ps1` and put it in Mods folder.
+You can find more information on [Winget-Install](https://github.com/Romanitho/Winget-Install) Repo, as it's a related feature
## Help
In some cases, you need to "unblock" the "install.bat" file (Windows Defender SmartScreen). Right click, properties and unblock. Then, you'll be able to run it.
From e3fc12109bc2023b7033b5bbb703669a27d7b8ed Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Sun, 24 Apr 2022 22:00:51 +0200
Subject: [PATCH 6/6] Minor changes on doc
---
README.md | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 0131fc1..dd2bf1b 100644
--- a/README.md
+++ b/README.md
@@ -73,15 +73,15 @@ Specify the Notification level: Full (Default, displays all notification), Succe
Remove scheduled tasks and scripts.
## Custom scripts (Mods feature)
-From version 1.8.0, The Mods feature allows you to run an additional script when installing or upgrading an app.
-Just put the script with the App ID followed by the "-install" or "-upgrade" suffix to be considered.
-Call `AppID-install.ps1` and/or `AppID-upgrade.ps1` (if it differs, otherwise the "-install" mod will be used for upgrade)
-and put this in the Mods directory
-> Example:
-> If you want to run a script that remove desktop shortcut just after installing "Google Chrome", prepare a powershell script that remove desktop shortcut, call your script like this:
-> `Google.Chrome-install.ps1` and put it in Mods folder.
+From version 1.8.0, the Mods feature allows you to run an additional script when upgrading or installing an app.
+Just put the script in question with the App ID followed by the "-upgrade" or "-install" suffix in the "mods" folder.
+WAU will call `AppID-upgrade.ps1` and/or `AppID-install.ps1` (if they differs, otherwise the "-install" mod will be used for upgrades too) if it exists in the "mods" folder just after the upgrade/install.
-You can find more information on [Winget-Install](https://github.com/Romanitho/Winget-Install) Repo, as it's a related feature
+> Example:
+If you want to run a script that removes the shortcut from "%PUBLIC%\Desktop" (we don't want to fill the desktop with shortcuts our users can't delete) just after installing "Acrobat Reader DC" (32-bit), prepare a powershell script that removes the Public Desktop shortcut "Acrobat Reader DC.lnk" and name your script like this:
+`Adobe.Acrobat.Reader.32-bit-install.ps1` and put it in the "mods" folder.
+
+You can find more information on Winget-Install Repo, as it's a related feature
## Help
In some cases, you need to "unblock" the "install.bat" file (Windows Defender SmartScreen). Right click, properties and unblock. Then, you'll be able to run it.