Board logo

标题: [转载代码] [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:
  1. function Play-Alarm {
  2.     $path = "$PSScriptRoot\Alarm06.wav"
  3.     $playerStart = New-Object Media.SoundPlayer $path
  4.     $playerStart.Load()
  5.     $playerStart.PlaySync()
  6. }
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.

欢迎光临 批处理之家 ( Powered by Discuz! 7.2