-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathToastNotification_Updater.ps1
77 lines (65 loc) · 2.21 KB
/
ToastNotification_Updater.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#Detection of version
$WingetID = '<WINGET ID>'
$processName = "<PROCESS NAME>"
$Apps = winget list --id $WingetID --exact --accept-source-agreements | Select-String "$WingetID" -SimpleMatch
$AppsOption1 = $Apps -split ("\s+") | Select-Object -Last 3 | Select-Object -First 1
$AppsOption2 = $Apps -split ("\s+") | Select-Object -Last 2 | Select-Object -First 1
$WingetData = winget show --id "$WingetID"
$Version = $WingetData | Select-String "Version: " | Select-Object -First 1
$WingetVersion = $Version -split (" ") | Select-Object -Last 1
#Check to see if application is up to date
if($AppsOption1 -eq $WingetID)
{
if([Version]$AppsOption2 -ge [Version]$WingetVersion)
{
Write-Output '1'
exit 0
}
}
elseif([Version]$AppsOption1 -ge [Version]$WingetVersion)
{
Write-Output '1'
exit 0
}
else
{
#Specify Launcher App ID
$LauncherID = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe"
[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
#Build XML Template
[xml]$ToastTemplate = @"
<toast duration="long">
<visual>
<binding template="ToastImageAndText03">
<text id="1">Update Required for Notepad++</text>
<text id="2">Please close the Application to start the update.</text>
</binding>
</visual>
<actions>
<action arguments="ignore" content="Ignore" activationType="foreground"/>
</actions>
</toast>
"@
#Prepare XML
$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
$ToastXml.LoadXml($ToastTemplate.OuterXml)
#Prepare and Create Toast
$Toast = [Windows.UI.Notifications.ToastNotification]::New($ToastXml)
if (Get-Process $processName -ErrorAction SilentlyContinue) {
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($Toast)
Start-Sleep 60
if (Get-Process $processName -ErrorAction SilentlyContinue)
{
Write-Host 'App is still open.'
}
else
{
Write-Output 1
}
}
else
{
Write-Output 1
}
}