How can I play a sound file from a Windows batch file?
Using the Windows mplay32.exe or mplayer.exe file included with Microsoft Windows allows you to play Windows sound files. Depending on your version of Windows will depend on what file you'll run. Windows 95 and 98 users will be using mplayer instead of mplay32 as shown in the below examples.
As can be seen in the example below we're using mplay32 as the program to play the file. The /play and /close switches are used to tell the program to play the file once open and then close when done. Finally, the remainder of the line is the full path to where the audio file is stored. In this example we're playing the Windows chimes file.
mplay32 /play /close c:\windows\media\chimes.wav
If the file and/or directory has a space in it make sure to include the full path in quotes as shown below.
mplay32 /play /close "c:\windows\media\windows xp error.wav"
Finally, this media player is only capable of playing .wav, .mid, *.cda, *.avi, *.asf files. If you're trying to play .mp3 files this program will not work. If you wish to play other media files you'll need to use an alternative command line media player that is not included with Windows.
Alternatively you can use the start command to start the program associated with the file. For example, if you wanted to open the player to play "music.mp3" in the command line or batch file you could type the below command.
Unfortunately this method would only open the file in the default player associated with .mp3 files and because the Windows player would not have a switch to automatically start the file it would not play the file until you clicked play.