I'm facing an issue on my powershell script. I use a notifyIcon to display some error message for a monitoring script. This is work perfectly. But i want to open a log file when I click on the notification. Unfortunately this not work when I click on the notification. When I click on the notifyIcon nothing happen. I try many solutions but nothing until now.
This is my code:
$global:balloon = New-Object System.Windows.Forms.NotifyIcon;
$path = (Get-Process -id $pid).Path;
$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path);
$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning;
$balloon.BalloonTipText = $msgAlert;
$balloon.BalloonTipTitle = "Monitoring";
$balloon.Visible = $true ;
$balloon_BalloonTipClicked={
Start notepad $LogFileName;
}
$balloon.ShowBalloonTip(5000);
Someone can help me please ? I tried many options like Add_click, MouseClick etc. Thank in Advance !
I tried again but nothing when I cliked on my notification.
Clear-Host
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
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 #Create the notification object
$global:balloon = New-Object System.Windows.Forms.NotifyIcon;
$balloon.Icon = [System.Drawing.SystemIcons]::Information
$balloon.BalloonTipIcon = "Info";
$balloon.BalloonTipText = $msgAlert;
$balloon.BalloonTipTitle = "Monitoring";
$balloon.Visible = $true ;
register-objectevent $balloon BalloonTipClicked BalloonClicked_event `
-Action {Start notepad $LogFileName;} | Out-Null
register-objectevent $balloon BalloonTipClosed BalloonClosed_event `
-Action {[System.Windows.Forms.MessageBox]::Show("Balloon message closed","Information");$notification.Visible = $False} | Out-Null
Maybe I miss something.
Based from the comment posted by Scepticalist : Balloon Notifications with Powershell
EDIT : Creating a Balloon Tip Notification Using PowerShell