As the target OS is windows 7, this code makes use of forfiles
to retrieve file time in seconds. The rest of the code is from a "run time meter" i was using. It will handle the midnight rollover but will not test for time difference over multiple days. Adapt as needed. This just returns the age in cents of second of the current batch file and this value formated as a usual time string.
@echo off
setlocal enableextensions disabledelayedexpansion
call :getFileTime "%~f0" fileTime
call :getElapsedTime "%fileTime%" "%time%" fileAge fileAgeFormatted
echo %fileAge% %fileAgeFormatted%
endlocal
exit /b
:getFileTime file returnVariable
for /f "tokens=*" %%a in ('forfiles /p "%~dp1." /m "%~nx1" /c "cmd /c echo @ftime"') do set "%~2=%%~a"
exit /b
:getElapsedTime time1 time2 returnVariableCent returnVariableTimeFormat
setlocal enableextensions
call :time2timestamp "%~1" t1
call :time2timestamp "%~2" t2
if %t2% gtr %t1% ( set /a "t=t2-t1" ) else ( set /a "t=8640000-t1+t2" )
if not "%~4"=="" set /a "h=100+ (t/360000)", "m=100+ (t-(h-100)*360000)/6000", "s=100+ (t-(h-100)*360000-(m-100)*6000)/100", "c=100+ (t %% 100)"
endlocal & (if not "%~3"=="" set "%~3=%t%") & (if not "%~4"=="" set "%~4=%h:~-2%:%m:~-2%:%s:~-2%,%c:~-2%") & exit /b 0
:time2timestamp timeValue returnVariable
setlocal enableextensions
if "%~1"=="" ( set "ts=%time%" ) else ( set "ts=%~1" )
if "%ts:pm=%"=="%ts%" ( set "adjust=0" ) else ( set "adjust=12" )
for /f "tokens=1-4 delims=:-.,apm " %%a in ("%ts%") do ( set "h=00%%a" & set "m=00%%b" & set "s=00%%c" & set "c=00%%d")
set /a "ts=(1%h:~-2%-100+adjust)*360000+(1%m:~-2%-100)*6000+(1%s:~-2%-100)*100+(1%c:~-2%-100)"
endlocal & set "%~2=%ts%" & exit /b 0
For the play sound part, as far as i know, there is not way of directly playing a custom wav from command line without spawning another process. The usual tools are vlc, wmplayer, a vbs file instancing the wmplayer ocx, sound recorder, powershell, ... All this options are documented in previous questions (just the first) here in stackoverflow or here in superuser.
Expanding one of the alternatives, if you have access to some C compiler (tested with mingw) this code will generate a console tool that calls the PlaySound
API function passing the first argument as the file to play.
#include <windows.h>
int main(int argc, char **argv)
{
if (argc < 2) return 1;
if (!PlaySound(
argv[1],
NULL,
SND_FILENAME | SND_NODEFAULT | SND_SYNC
)
) return 2;
return 0;
}
Depending of your configuration you will need to include a reference to the Winmm library to the linker.