1
[reflection.assembly]::loadwithpartialname("System.Windows.Forms")
[reflection.assembly]::loadwithpartialname("System.Drawing")
$notify = new-object system.windows.forms.notifyicon
$notify.icon = [System.Drawing.SystemIcons]::Information
$notify.visible = $true
$notify.showballoontip(10,"Warning","The CPU is hot.",[system.windows.forms.tooltipicon]::None)
The above Powershell script brings up a toast notification. After it has disappeared, its icon remains in the notification area permanently. How can the icon be removed automatically without having to hover the cursor over it? Or can the line $notify.icon = [System.Drawing.SystemIcons]::Information
be safely removed so that the script can work without the icon, which is dispensable?
None of the following works either.
$notify.icon = $false
notifyicon.visible = false
$notify.icon = null
$notify.visible = null
notifyIcon = null
notifyIcon.icon = null
$notifyIcon.dispose()
notifyIcon.Dispose
1put
$objNotifyIcon.Visible = $False
at the end? – Mokubai – 2016-12-26T13:34:25.3631what you're looking for is the
.dispose()
method. use$objNotifyIcon.dispose()
at the bottom of the script and it will get rid of the icon. – SimonS – 2016-12-26T18:13:06.203@ Mokubai and SimonS, I have just changed the PowerShell script in my question, so please read it again. Both of your suggestions do not work on the revised script. – Matthew Wai – 2016-12-27T14:20:38.913
$notify.dispose()
works when i test it. – SimonS – 2016-12-27T22:40:08.170$notify.dispose()
works when toast notifications are used but does not work when balloon notifications are used. Test it yourself. – Matthew Wai – 2016-12-28T09:40:57.997i tested your code and dispose and it worked :D – SimonS – 2016-12-28T11:36:23.110
Before the test, did you change toast notifications to balloon notifications as described in link? At my end,
– Matthew Wai – 2016-12-28T13:40:03.910$notify.dispose()
works on toasts but not on balloon.$objNotifyIcon.dispose()
did it – Yoraco Gonzales – 2018-09-07T17:18:10.037I have put
$objNotifyIcon.dispose()
at the bottom of the script, but it does not work. The icon remains there. – Matthew Wai – 2018-09-09T02:10:07.503