-
Notifications
You must be signed in to change notification settings - Fork 8
/
wlanprofilemanager-notify.ps1
70 lines (53 loc) · 2.26 KB
/
wlanprofilemanager-notify.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
<#
.SYNOPSIS
Display a notification (balloon/toast) to the user
.DESCRIPTION
This script will display the content of .notify file as a toast to the user.
In order to work, this script should be run as the current user (and not as SYSTEM or other account).
Based on https://github.com/proxb/PowerShell_Scripts/blob/master/Invoke-BalloonTip.ps1
.INPUTS
File .notify
.OUTPUTS
None
.NOTES
Version: 1.0
Author: Indigo744
Creation Date: 24 april 2019
Purpose/Change: Initial script release
#>
#---------------------------------------------------------[External Modules]-------------------------------------------------------
Import-Module "./wlanprofilemanager-ps.psm1" -Force
#-----------------------------------------------------------[Execution]------------------------------------------------------------
$notification_content = NotifyFileGet
if ($notification_content) {
# Create a new object
Add-Type -AssemblyName System.Windows.Forms
$global:balloon = New-Object System.Windows.Forms.NotifyIcon
try {
# Mouse double click on icon to dispose
[void](Register-ObjectEvent -InputObject $global:balloon -EventName MouseDoubleClick -SourceIdentifier IconClicked -Action {
$global:balloon.Visible = $false
$global:balloon.dispose()
Unregister-Event -SourceIdentifier IconClicked
Remove-Job -Name IconClicked
Remove-Variable -Name balloon -Scope Global
})
# Need an icon for tray, use process path to get its icon (powershell icon)
$process_path = Get-Process -id $pid | Select-Object -ExpandProperty Path
$global:balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($process_path)
# Set other parameters
$global:balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Info
$global:balloon.BalloonTipText = $notification_content
$global:balloon.BalloonTipTitle = "wlanprofilemanager"
# Show the tooltip with a timeout
$global:balloon.Visible = $true
$global:balloon.ShowBalloonTip(3000)
Start-Sleep -Seconds 3
}
finally {
If ($global:balloon) {
$global:balloon.Visible = $false
$global:balloon.Dispose()
}
}
}