I have a Powershell function that shows a balloon tip and it works fine, except for two things. First, is there a way to have my script display a message to every logged-in user?
Second, according to several blog posts (like this and this), I should be cleaning up my icon. The sample code doesn't seem to work for me. Regardless of how I click the balloon, the icon says in place. If I hover my mouse over the icon (with or without closing the balloon), the icon disappears. Am I missing something here?
Thanks.
Function Start-LogoffNotice { <# .SYNOPSIS Displays a notice in the Windows notification area. #> param ( $IconPath = (Get-Process -id $pid | Select-Object -ExpandProperty Path), [ValidateSet("Info","Warning","Error","None")] $BalloonIcon, $BalloonText, $BalloonTitle, $BalloonTimeout = "60000" ) Add-Type -AssemblyName System.Windows.Forms | Out-Null $objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon $objNotifyIcon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($IconPath) $objNotifyIcon.BalloonTipIcon = $BalloonIcon $objNotifyIcon.BalloonTipText = $BalloonText $objNotifyIcon.BalloonTipTitle = $BalloonTitle $objNotifyIcon.Visible = $True $objNotifyIcon.ShowBalloonTip($BalloonTimeout) #This section doesn't seem to do anything. Register-ObjectEvent -InputObject $objNotifyIcon -EventName BalloonTipClosed -Action { Unregister-Event $objNotifyIcon.SourceIdentifier Remove-Job $objNotifyIcon.Action $objNotifyIcon.Dispose() } | Out-Null } Start-LogoffNotice -BalloonIcon "Info" -BalloonText "You will be logged off in 1 minute. Please save your work." -BalloonTitle "Logoff Notice"