假設你有一個名爲音樂你的腳本中,這樣你就可以使用相對路徑是這樣./Music/Matrix.mp3
文件夾
所以,你可以給這樣的嘗試:
Option Explicit
Dim Msg,Question,PathSound
Msg = "Did you want to hear some music ?"
PathSound = "./Music/Matrix.mp3" 'Relative Path
Question = MsgBox(Msg,VbQuestion+VbYesNo,Msg)
If Question = VbYes Then
Call Play(PathSound)
Else
Wscript.Quit()
End If
'**********************************************************
Sub Play(SoundFile)
Dim Sound
Set Sound = CreateObject("WMPlayer.OCX")
Sound.URL = SoundFile
Sound.settings.volume = 100
Sound.Controls.play
do while Sound.currentmedia.duration = 0
wscript.sleep 100
loop
wscript.sleep(int(Sound.currentmedia.duration)+1)*1000
End Sub
'**********************************************************
如果你喜歡在網上播放的音樂,所以你可以做這樣的:
Option Explicit
Dim Msg,Question,PathSound
Msg = "Did you want to hear some music ?"
PathSound = "http://hackoo.alwaysdata.net/Matrix.mp3"
Question = MsgBox(Msg,VbQuestion+VbYesNo,Msg)
If Question = VbYes Then
Call Play(PathSound)
Else
Wscript.Quit()
End If
'**********************************************************
Sub Play(SoundFile)
Dim Sound
Set Sound = CreateObject("WMPlayer.OCX")
Sound.URL = SoundFile
Sound.settings.volume = 100
Sound.Controls.play
do while Sound.currentmedia.duration = 0
wscript.sleep 100
loop
wscript.sleep(int(Sound.currentmedia.duration)+1)*1000
End Sub
'**********************************************************
我希望這個回答能幫助你完成你的主腳本;)
這很好用!有什麼辦法可以讓延遲/睡眠時間縮短嗎?我嘗試了兩種睡眠功能,但它給了我一些不可思議的結果(在單擊msgbox上單擊確定後播放聲音)。現在聲音正在播放,然後幾秒鐘後msgbox出現。我希望聲音儘可能接近msgbox播放。 – Jared
@Jared在這種情況下,你應該upvote這個答案並接受它。 欲瞭解更多信息,請閱讀此==> http://stackoverflow.com/tour – Hackoo