我在powershell脚本上遇到了一个问题。我使用一个notifyIcon来显示监视脚本的一些错误消息。这是完美的工作。但我想打开一个日志文件时,我点击通知。不幸的是,这不工作时,我点击通知。当我点击notifyIcon什么也没有发生。我尝试了许多解决方案,但直到现在什么也没有。
这是我的代码:
$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);
有人可以帮助我吗?我尝试了许多选项,如添加_单击,鼠标单击等,提前感谢!
我又试了一次,但当我点击我的通知。
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
也许我错过了什么。
1条答案
按热度按时间lzfw57am1#
基于***怀疑论者***发表的评论:Balloon Notifications with Powershell
编辑:***Creating a Balloon Tip Notification Using PowerShell***