How to play a sound file from a Windows batch file

Updated: 12/09/2018 by Computer Hope

Batch fileIf you're running a batch file on your computer, it can be useful to play audio on your computer speakers, as a notification or alarm. You can use the start command in your batch file to launch an audio application and play the sound, audio recording, or music that you'd like to hear.


If you would like to the player to open and play "music.mp3" in the command line or batch file, you could type the following command.

start music.mp3

If the sound file has a space in the file name, surround the file name in quotes as shown in the following example.

start "c:\music\my song.mp3"

Tip: Using the start command opens the file in the default audio player, which means by default, audio files open in Windows Media Player. However, if the computer has a different audio program that has re-associated the audio files, the other program is used instead. If you want Windows Media Player to play the audio file regardless of what other audio players are installed, continue to the next section.

Alternative solution

The Windows Media Player can be run from the command line, or in a batch file, to play sound files. In Windows 10, the Media Player executable file is located at Program Files (x86)\Windows Media Player\wmplayer.exe. In previous versions of Windows, the Media Player executable was named mplay32.exe or mplayer.exe. Windows 95 and 98 users should use mplayer. Windows XP and 2000 users should use mplay32 (as shown in the following examples), and Windows Vista and Windows 7 users should use wmplayer.

Windows Vista, Windows 7, and Windows 8 wmplayer examples

The following command will cause Windows Media Player to open and play the audio file example.mp3.

start wmplayer c:\mp3\example.mp3

As in this example, you should always specify the complete path to the audio file, including the drive letter. If the directory or audio file name has a space in it, make sure to enclose the entire path and file name in double quotes, for example:

start wmplayer "c:\mp3\example audio.mp3"

Where is the wmplayer /close option?

Unfortunately, Microsoft has not included a /close option for wmplayer. If you need a close option to run a series of different files, you may consider using the "/Playlist PlaylistName" switch to have Windows Media Player play a playlist. Alternatively, you can use another media player program, such as MPC-HC, which does have a /close option.

Windows XP and 2000 mplay32 examples

As can be seen in the following example, we are using mplay32 as the program to play the file. The /play and /close switches are used to tell the program to play the file 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 are playing the Windows chimes file.

mplay32 /play /close c:\windows\media\chimes.wav

If the file or directory has a space in it, make sure to include the full path in quotes, as shown.

mplay32 /play /close "c:\windows\media\windows xp error.wav"

Earlier versions of the Media Player (mplayer) can only play .wav, .mid, .cda, .avi, and .asf files. If you are trying to play .mp3 files or other audio files, this program will not work. If you need to play other media files, use an alternative command line media player that is not included with Windows. The later version of Windows wmplayer command is capable of playing .mp3 files, as well as all other media files Windows Media Player is capable of playing.

Playing sound with a custom audio program

To play an audio file in a different media player, set the path to the directory of where the alternative media player is located or move into the directory that contains the audio file. Otherwise, you will get an error message indicating that the command is not recognized.

For example, if you would like to play an MP3 file in the VLC media player, you could move to the C:\Program Files\VideoLan\VLC directory or add the directory to your path. From this directory, type the following command to execute and start playing the MP3 file in VLC. Keep in mind that the mplay32 options mentioned above (/play and /close) do not work for every media player, including VLC.

vlc "c:\music\my song.mp3"

Additional information