0
我想处理System.Windows.Forms.NotifyIcon的BalloonTipClicked。也就是说,我想在点击提示时处理事件。我的代码在下面,但我无法赶上事件。请帮忙 !powershell 2事件处理
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Timers")
## This is the location of your download files
$notification = "E:\TDdownload"
$notification = New-Object System.Windows.Forms.NotifyIcon
$notification.Icon = "C:\Users\Sefler\Desktop\PerfCenterCpl.ico"
$notification.BalloonTipIcon = "Info"
$notification.BalloonTipText = "Windows will now try to clean "+ $fileLocation +" as scheduled."
$notification.BalloonTipTitle = "Windows auto maintaince"
$notification.Visible = $True
$notification.ShowBalloonTip(15000)
## Register a click event
register-objectevent $notification BalloonTipClicked -sourceIdentifier notification_event
## Wait for the onClick event
wait-event -timeout 15
我提到过,但问题是它无法捕捉事件。正如我的代码所示,一旦发生,脚本就不会等待15秒。但我的脚本总是等待15秒。 – Sefler 2010-01-22 15:23:20
它让我疯狂!当我尝试在PowerShell ISE中运行你的vesion和我的。两个作品!但是,当我在正常的PowerShell窗口中运行它们时,它们都不起作用!我在两台电脑上尝试过它们。一个是Windows 7 Pro,另一个是Vista Home Basic。我只是不明白为什么! – Sefler 2010-01-22 17:06:02
尝试使用选项-STA启动Powershell.exe。 – 2010-01-22 18:02:27