Playing a .wav file in the background

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Posts: 11
Joined: 03 Feb 2014 02:39

Playing a .wav file in the background

#1 Post by stephjo » 03 Feb 2021 08:54

I have a high pitch "tada.wav" file that I'd like Windows to play in the background whenever I call it in my batch file.

I want the file to play without opening any window or launching an application ... just like the default way Windows plays "you-got-mail.wav" or "chimes.wav" or other files in C:\Windows\Media

Thank you.

Posts: 134
Joined: 06 May 2020 10:14

Re: Playing a .wav file in the background

#2 Post by T3RRY » 03 Feb 2021 09:58

The following script creates a vbs script to do such.
Only tested on windows 10, assumes the default windows media player is installed.

Code: Select all

::: Author: T3RRY Name: PlayMusic.bat
::: [ creates a companion vbs file that's called with arguments For trackpath, volume and loop t/f values
::: Parameters required For Player: [filepath.ext] [0-100] [1{True}0-{False}]
 If "%~1" == "" (
  Echo %~n0 Usage:
  Echo/Call "%~nx0" "filepath.ext" 0-100 1^|0
  Echo/Arg 3: 1^|0 flags loop true/false respectively
  Exit /B
 If Not exist "%~1" (
  Echo/Track "%~1" Not found
 Set "MusicPath=%~1"
 For %%T in ("%~1")Do Set "trackname=%~n1"
 Set /A vol=Loop_TF=0
 Set /A "vol+=%~2 + 0" 2> nul
::: Defaults to no loop if no 3rd Arg
 Set /A "Loop_TF=%~3 + 0" 2> nul
 Setlocal EnableDelayedExpansion
 IF Not !Vol! GTR 0 (  Cls & Echo/Invalid "%~2" - Integer GTR 0 LEQ 100 required for arg %%2 ; Volume & Pause & Exit)
 IF Not !Vol! LEQ 100 (Cls & Echo/Invalid "%~2" - Integer GTR 0 LEQ 100 required for arg %%2 ; Volume & Pause & Exit)
 IF !Loop_TF! GTR 1 (Cls & Echo/Invalid "%~3" - Integer 0 or 1 required for arg %%3 ; Loop True / False & Pause & Exit)
::: - Change to the Directory the script and sound files are in.
 PUSHD "%~dp0" 
::: - Creates a vbs Script to Launch the music (Occurs without any visual indication or prompting)
  If not exist "Play_%trackname%.vbs" (
   >"Play_%trackname%.vbs" (
   echo Set Sound = CreateObject^("WMPlayer.OCX.7"^)
   echo Sound.URL = "%MusicPath%"
   echo Sound.settings.volume = %vol%
   echo Sound.settings.setMode "loop", %Loop_TF%
   echo While Sound.playState ^<^> 1
   echo WScript.Sleep 100
   echo Wend
 start /min "" "Play_%trackname%.vbs"
Note: I use this as part of a library that also includes a vbs monitor of the CMD process to call a cleanup script to ensure music played on a loop is closed when the cmd console is closed.
An example of this in use and a link to the libray it's included in can be found here:

Posts: 375
Joined: 16 Jul 2013 12:00
Location: HSV

Re: Playing a .wav file in the background

#3 Post by Samir » 11 Feb 2021 14:55

At one point back in the day when I had some free passes to COMDEX in Atlanta right at around the time Win95 was released, myself and 2x friends unleashed a script at the Microsoft booth that after 30 minutes would play the 'start me up' song and then change the boot image to windows F***ing 95 and reboot automatically after 10 minutes. We never saw the results of it as we injected our creation and left, but I'm sure it must have had those ditsy interns (aka models) in a panic, lol.

Anyways, today such an activity is pretty easy thanks to ole and the start command. The following should do what you want:

Code: Select all

START /MIN C:\Windows\Media\chimes.wav

Posts: 4090
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Playing a .wav file in the background

#5 Post by aGerman » 11 Feb 2021 15:49

SPEAK.BAT wraps quite some functionality of the Speech API, which includes playing wave files:


Post Reply