Show failure to launch?

Howdy,

I’ve a script that fails to kick off a Show method. My objective is to show a balloon message in the system tray and to pop up a Show message whether I click on or kill the balloon. Eventually the Show message will have miscellaneous information added to it. When I run my script I get my balloon message, my icon shows in the systray but when I click or kill the baloon the show doesn’t kick off and the icon stays in the systray. When I hover over the icon it immediately disappears. Settings for my balloon are 'Show Icon and Notifications (alongside the ‘Power Shell’ label).

Advice or pointers welcome

# Load forms
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

# Get rid of old registrations
Remove-Event BalloonClicked_event -ea SilentlyContinue
Unregister-Event -SourceIdentifier BalloonClicked_event -ea silentlycontinue
Remove-Event BalloonClosed_event -ea SilentlyContinue
Unregister-Event -SourceIdentifier BalloonClosed_event -ea silentlycontinue

# my object
$notify = New-Object System.Windows.Forms.NotifyIcon

# Cusom icon
$notify.Icon = 'C:\Users\timw\Documents\Baloons\nr16.ico'

# Title balloon
$notify.BalloonTipTitle = "Status Tracking Notification"

# Info icon
$notify.BalloonTipIcon = "Info"

# Big ugly message
$title = "z100m11 This is the message in the balloon tip. This is sentence two in the baloon tip. sentence 3 is here...."
$notify.BalloonTipText = $title

# SHow baloon
$notify.Visible = $True

## Events to handle two kinds of exists.

# Clicked

register-objectevent $notify BalloonTipClicked BalloonClicked_event `
-Action { [System.Windows.Forms.MessageBox]::Show("Balloon message
clicked","Information"); $notify.Visible = $False } | Out-Null

# Closed

register-objectevent $notify BalloonTipClosed BalloonClosed_event `
-Action { [System.Windows.Forms.MessageBox]::Show("Balloon message
closed","Information"); $notify.Visible = $False } | Out-Null

# Longish show (in ms)
$notify.ShowBalloonTip(10000) ;

 

never did any of the above, but can you try something to a file on the close event just to make sure the event listens and trigger something.
Just to check if it supports only non-interactive actions or not.

I’m not sure if this is will work, I modified the action to both close and clicked events to copy-Item hoping the event would copy a file.

register-objectevent $notify BalloonTipClicked BalloonClicked_event `
-Action { Copy-Item "C:\users\trw\temp\temporig.txt" -Destination "C:\users\trw\temp\tempcopy.txt" }

When I run the script I get output like , neither event copies a file.

Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
73 BalloonClick... NotStarted False Copy-Item "C:\users\t...
74 BalloonClose... NotStarted False Copy-Item "C:\users\...

Unfortunately I don’t know powershell so this is kind of a guess.

What OS and PowerShell version are you using?

In testing your code on one of my Win10/PSv5x system, in either the ISE/VSCode/consolehost, the messagebox (from your show event) appears whether I click the balloon, or click the arrow to dismiss it. Actually, clicking anywhere on the screen dismisses the balloon on Windows by default, that is not your code, but even that still fires you message box. If you wait for the timer to fire, the balloon of course goes away and the message box appears.

Hovering of the default icon, does nothing, and shouldn’t, since you have no actions to handle hover. Meaning, this ‘hover over the icon it immediately disappears.’, does not happen in the system I tested this on.

As for this…

Settings for my balloon are 'Show Icon and Notifications (alongside the 'Power Shell' label).

… where are you setting this? It not in the code you posted, and looking at all of my PowerShell code I’ve done or collected on this topic, I see no apparent way of getting all that you are after, they way you have explained your use case.

Also, take a look at the BurntToast module to see is that gets you where you need to go. Take a look at is code.

Find-Module -Name '*toast*' | fl -Force


Name                       : BurntToast
Version                    : 0.7.0
Type                       : Module
Description                : Module for creating and displaying Toast Notifications on Microsoft Windows 10.
Author                     : Joshua (Windos) King
CompanyName                : Windos
Copyright                  : (c) 2015 Joshua (Windos) King. All rights reserved.
PublishedDate              : 4/1/2019 8:28:18 AM
InstalledDate              : 
UpdatedDate                : 
LicenseUri                 : https://github.com/Windos/BurntToast/blob/master/LICENSE
ProjectUri                 : https://github.com/Windos/BurntToast
IconUri                    : https://raw.githubusercontent.com/Windos/BurntToast/master/Media/BurntToast-Logo.png
Tags                       : {Notifications, Utilities, Windows10, Toast, PSModule}
Includes                   : {Function, RoleCapability, Command, DscResource, Workflow, Cmdlet}
PowerShellGetFormatVersion : 
ReleaseNotes               : # 0.7.0
                             
                             * HEADLINE FEATURE: My People "Shoulder Tap" notifications have been implemented
                             * You can now specify images on the network via UNC paths. Fix for #56
                             * We're now properly supporting bindable text, and removing the curly braces more gracefully
                             * Get a list of all toasts you've sent, which have not been dismissed by the user, using Get-BTHistory
                             * Remove toasts you've sent, using Remove-BTNotification
                             * Set expiration times on toasts using the new ExpirationTime parameter on New-BurntToastNotification and 
                             Submit-BTNotification
                               * Toasts which have expired are removed from the Action Center
                             * Send toasts directly to the Action Center, and avoid showing them on screen, with the new SuppressPopup 
                             switch on New-BurntToastNotification and Submit-BTNotification
                             * You can now adjust a toasts timestamp (both past and future) using the CustomTimestamp parameter on 
                             New-BurntToastNotification and New-BTContent
                               * If not specified, the system uses the time at which the toast was received and this may not accuratly 
                             reflect the intent of the notification
Dependencies               : {}
RepositorySourceLocation   : https://www.powershellgallery.com/api/v2
Repository                 : PSGallery
PackageManagementProvider  : NuGet
AdditionalMetadata         : @{summary=Module for creating and displaying Toast Notifications on Microsoft Windows 10.; 
                             downloadCount=50728; created=4/1/2019 8:28:18 AM -07:00; description=Module for creating and displaying 
                             Toast Notifications on Microsoft Windows 10.; copyright=(c) 2015 Joshua (Windos) King. All rights 
                             reserved.; FileList=BurntToast.nuspec|BurntToast.psd1|BurntToast.psm1|config.json|README.md|Images\BurntToa
                             st-Logo.png|Images\BurntToast.png|lib\Microsoft.Toolkit.Uwp.Notifications\Microsoft.Toolkit.Uwp.Notificatio
                             ns.dll|lib\Microsoft.Toolkit.Uwp.Notifications\Microsoft.Toolkit.Uwp.Notifications.xml; 
                             lastUpdated=6/9/2019 1:55:50 AM -07:00; published=4/1/2019 8:28:18 AM -07:00; tags=Notifications Utilities 
                             Windows10 Toast PSModule; releaseNotes=# 0.7.0
                             
                             * HEADLINE FEATURE: My People "Shoulder Tap" notifications have been implemented
                             * You can now specify images on the network via UNC paths. Fix for #56
                             * We're now properly supporting bindable text, and removing the curly braces more gracefully
                             * Get a list of all toasts you've sent, which have not been dismissed by the user, using Get-BTHistory
                             * Remove toasts you've sent, using Remove-BTNotification
                             * Set expiration times on toasts using the new ExpirationTime parameter on New-BurntToastNotification and 
                             Submit-BTNotification
                               * Toasts which have expired are removed from the Action Center
                             * Send toasts directly to the Action Center, and avoid showing them on screen, with the new SuppressPopup 
                             switch on New-BurntToastNotification and Submit-BTNotification
                             * You can now adjust a toasts timestamp (both past and future) using the CustomTimestamp parameter on 
                             New-BurntToastNotification and New-BTContent
                               * If not specified, the system uses the time at which the toast was received and this may not accuratly 
                             reflect the intent of the notification; Authors=Joshua (Windos) King; ItemType=Module; 
                             PackageManagementProvider=NuGet; versionDownloadCount=13841; updated=2019-06-09T01:55:50Z; 
                             CompanyName=king.geek.nz; developmentDependency=False; NormalizedVersion=0.7.0; PowerShellVersion=5.0; 
                             title=BurntToast; GUID=751a2aeb-a68f-422e-a2ea-376bdd81612a; isLatestVersion=True; Functions=Get-BTHistory 
                             New-BTAction New-BTAppId New-BTAudio New-BTBinding New-BTButton New-BTContent New-BTContextMenuItem 
                             New-BTHeader New-BTImage New-BTInput New-BTProgressBar New-BTSelectionBoxItem New-BTShoulderTapBinding 
                             New-BTShoulderTapImage New-BTShoulderTapPeople New-BTText New-BTVisual New-BurntToastNotification 
                             New-BurntToastShoulderTap Remove-BTNotification Submit-BTNotification Update-BTNotification; 
                             requireLicenseAcceptance=False; isAbsoluteLatestVersion=True; IsPrerelease=false; packageSize=204286; 
                             SourceName=PSGallery}


So, does this …

Unfortunately I don't know powershell so this is kind of a guess.

… mean, you’ve spent no real time learning PowerShell prior to doing this?

If so, please, save yourself the frustration, misconceptions, unnecessary hair-pulling, errors, bad habits, etc., and jump on YouTube, or MSDN channel9 and grow thru the videos for beginning/intermediate/advanced PowerShell, PowerShell GUI, PowerShell using .Net, etc., to get a better/firmer grounding on it.