标题: [转载代码] [PowerShell每日技巧]遇到报错时播放提示音(20140129) [打印本页]
作者: DAIC 时间: 2014-2-17 10:16 标题: [PowerShell每日技巧]遇到报错时播放提示音(20140129)
To catch a user’s attention, your script can easily play WAV sound files. Here is a simple function:- function Play-Alarm {
- $path = "$PSScriptRoot\Alarm06.wav"
- $playerStart = New-Object Media.SoundPlayer $path
- $playerStart.Load()
- $playerStart.PlaySync()
- }
复制代码
It assumes the WAV file is located in the same folder the script is saved in. Note that $PSScriptRoot is not supported in PowerShell 2.0.
Just make sure you rename the $path variable and have it point to any valid WAV file you want to use.
By default, PowerShell will wait until the sound is played. Replace PlaySync() with Play() if you want PowerShell to continue and not wait.
http://powershell.com/cs/blogs/tips/archive/2014/01/29/playing-a-sound-on-error.aspx
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |