I am trying to play a sound file from within a VBScript when a certain msgbox appears. The only problem is that I will be sending this elsewhere and the person who receives it won't have the same pathname as the audio file that I want to play. I was thinking about putting all of the sound files that I want to use in the same folder as the script and then sending that folder, but I don't know how to make sure the sound file will play.
So I guess the biggest question is how to generalize the pathname so that anyone can hear the file from within the script from any machine.
Here is my code so far:
if intAnswer3 = vbyes then
strSoundFile = "C:\pathname"
Set objShell = CreateObject("Wscript.Shell")
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, True
Assume that you have a folder named Music with your script, so you can use a relative path like this ./Music/Matrix.mp3
So you can give a try like this :
And if you like to play the music online, so you can do it like this :
I hope that this answer can help you to complete your main script ;)
Did you mean something like that :
Description : This Vbscript "PlayListSongs.vbs" scan into a folder and its subfolders for songs and create a playlist in a text file in order to play it in background.
Update : I add another vbscript to stop and kill the "wscript.exe" process in order to stop music playing in background.
I add another vbscript to play the playlist with Windows Media Player in foreground.
in sum you can found into zip 3 vbscript
1- To play the playlist in the background.
2- To Stop the music.
3- To Play the music with Windows Media Player in foreground.
So you can download it from here and test it