用于显示通知气球并采取措施的PowerShell脚本仅在ISE gui中起作用,而不能在命令行中起作用
||
我看过很多密切相关的帖子,所以我知道我并不孤单,但是没人能给我答案。很抱歉,如果有人提出并回答了这个问题,而我找不到它。
此脚本会创建一个自定义通知区域气球,如果单击该气球,则将打开一个指向某些URL的新IE窗口。我已经在其中使用过的PowerShell ISE GUI可以很好地工作。使用我在其他文章中建议的任何选项,都无法使其从命令行运行。具体来说,无法打开IE窗口。通知似乎没有问题,但是没有IE窗口... ??尝试过:
电源外壳 。 script.ps1
powershell-文件script.ps1
命令
和
等等
有什么想法吗?
我的剧本:
#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)
没有找到相关结果
已邀请:
3 个回复
茶鬼失形
祁澈盘哼颗
导力疵谜
参数启动
(即控制台窗口)。 Windows GUI代码需要在设置为COM \“ Single Threaded Apartment \”(STA)的线程中运行,但是默认情况下,PowerShell控制台中的工作线程在\“ Multi Threaded Apartment \”(MTA)中运行。