Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBS Play Sound With no Dialogue

Tags:

vbscript

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
like image 886
Carl479 Avatar asked Dec 11 '22 07:12

Carl479


1 Answers

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
like image 180
Helen Avatar answered Feb 08 '23 23:02

Helen