Jor*_* W. 5 powershell notifications powershell-ise powershell-2.0 windows-7
我看过一堆密切相关的帖子,所以我知道我并不孤单,但没有人给我我正在寻找的答案。如果有人问过并回答过这个问题而我找不到它,我深表歉意。
此脚本创建一个自定义通知区域气球,如果单击该气球,将打开一个指向某个 URL 的新 IE 窗口。在我一直在使用它的 PowerShell ISE GUI 中效果很好。无法使用我在其他帖子中看到的任何选项从命令行运行。具体来说,无法打开 IE 窗口。通知出现没有问题,但是没有IE窗口...??尝试过:
等等。
想法?
我的脚本:
#Load the required assemblies
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
#Remove any registered events related to notifications
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
Remove-Event Disposed -ea SilentlyContinue
Unregister-Event -SourceIdentifier Disposed -ea silentlycontinue
#Create the notification object
$notification = New-Object System.Windows.Forms.NotifyIcon
#Define various parts of the notification
$notification.Icon = [System.Drawing.SystemIcons]::Information
$notification.BalloonTipTitle = “**Reminder**”
$notification.BalloonTipIcon = “Warning”
$title = “message to user”
$notification.BalloonTipText = $title
#Make balloon tip visible when called
$notification.Visible = $True
## Register a click event with action to take based on event
#Balloon message clicked
register-objectevent $notification BalloonTipClicked BalloonClicked_event -Action {
Start-Process 'c:\Program Files\Internet Explorer\iexplore.exe' -ArgumentList 'http://someURL.com' -WindowStyle Maximized -Verb Open
#Get rid of the icon after action is taken
$notification.Dispose()
} | Out-Null
#Balloon message closed
register-objectevent $notification BalloonTipClosed BalloonClosed_event -Action {$notification.Dispose()} | Out-Null
#Call the balloon notification
$notification.ShowBalloonTip(1000)
Run Code Online (Sandbox Code Playgroud)
小智 4
之所以在非交互式提示中不起作用,是因为当用户单击气球时,powershell 已经完成处理。
您可以通过以下两种方法之一修复该问题:
| 归档时间: |
|
| 查看次数: |
8681 次 |
| 最近记录: |