打开消息框并随机播放声音


你可能已经看到下面的脚本。现在,你用这段代码打开了一个消息窗体将同时随机播放了一段声音,是不是增加了一点娱乐吸引力。当用户结束消息窗体时声音将停止。

# find random WAV file in your Windows folder
$randomWAV = Get-ChildItem -Path C:\Windows\Media -Filter *.wav | 
  Get-Random |
  Select-Object -ExpandProperty Fullname

# load Forms assembly to get a MsgBox dialog
Add-Type -AssemblyName System.Windows.Forms

# play random sound until MsgBox is closed
$player = New-Object Media.SoundPlayer $randomWAV
$player.Load();
$player.PlayLooping()
$result = [System.Windows.Forms.MessageBox]::Show("We will reboot your machine now. Ok?", "PowerShell", "YesNo", "Exclamation")
$player.Stop()

原文地址:Open MsgBox with Random Sound

×用微信扫描并分享
本文链接: https://www.pstips.net/open-msgbox-with-random-sound.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

邮箱地址不会被公开。 必填项已用*标注