Reputation: 519
Is there a way to open a sound in VBS and without a dialogue?
This is my code...
intAnswer = _
Msgbox("Do you want to play welcome.mp3?", _
vbYesNo, "Play Song?")
If intAnswer = vbYes Then
Msgbox "Opening..."
`play %userprofile%/directory/welcome.mp3 with no dialogue`
Else
Msgbox "Not opening..."
End If
Upvotes: 4
Views: 32281
Reputation: 15
I know that the post was released five years ago, but for anyone who's still wondering here's the code:
do
set WshShell = CreateObject("WScript.Shell")
music = "C:\example.mp3"
WshShell.Run "wmplayer """ & music & """",0,True
loop
Save it as .vbs
file.
It is much simpler way and not very confusing. Works on Windows 7/10/11. Anything below i did not test.
Upvotes: 0
Reputation: 97609
You can play MP3 files in VBScript using the Windows Media Player scripting object, WMPlayer.OCX
.
Dim oPlayer
Set oPlayer = CreateObject("WMPlayer.OCX")
' Play audio
oPlayer.URL = "C:\welcome.mp3"
oPlayer.controls.play
While oPlayer.playState <> 1 ' 1 = Stopped
WScript.Sleep 100
Wend
' Release the audio file
oPlayer.close
Upvotes: 13