windowsbatch-filecmdwinamp

Second Timeout function didn`t work in Batch File


Working on a startup File (like a shortcut with special functions) for a game. (Counter-Strike Global Offensive)

The intention is to replace the menu music - some updates ago this was easier but right now I need to forging on a Batch file.

This is how it looks so far

@Echo off
"C:\Users\Cedo\Desktop\csgo\csgo\Counter-Strike Global Offensive.url"
Timeout 9
"C:\Users\Cedo\Desktop\csgo\csgo\csgomusic.m3u8"
[Timeout 240]!
[Taskkill /IM winamp.exe]! ----> Dont work! 
Exit

and the way to here is more complicated than I thought. I solved already a lot of problems because a lot of the stuff on the internet seems outdated I guess.

The actual problem is a second timeout and taskkill for the winamp music file. Strangely when inserting a second timeout (like the first) nothing happens. Just after closing winamp manually the Timer starts!

But something needs to be done so that the second timeout with 240 secs and the taskkill to close winamp automatically works.

Another cool thing would be to start the winamp music file a bit later without minimizing the started game window. (Already tried start /min commands - it doesn't matter actually - wont work if minimized or maximized) Does someone know more? Right now I'm good with 9 Seconds(winamp opens before the game maximizes because this takes some time and so i didn`t get tabbed out).

And is there maybe a better way to build this up or improve things?


Solution

  • Just after closing winamp manually the Timer starts!

    Given this statement I infer that "C:\Users\Cedo\Desktop\csgo\csgo\csgomusic.m3u8" is starting Winamp.

    Note place the following script into the "C:\Users\Cedo\Desktop\csgo\csgo\" folder, or update the "_RootFolder" to have the correct path.

    So essentially what you need to do is this:

    Start a separate command window to run the task to kill winamp, because otherwise you will only move on tot the next command when Winamp is killed manually.

    @(SETLOCAL 
      REM SET "KillCmd="%~f0" :Kill_Winamp"
      REM SET "_StartKillCMD=start "Kill Winamp!" cmd /c %KillCmd%"
      SET "_StartKillCMD=start "Kill Winamp!" cmd /c "%~f0" :Kill_Winamp"
      SETLOCAL EnableDelayedExpansion
      ECHO OFF
      SET "eLvl=0"
      REM SET "_RootFolder=%USERPROFILE%\Desktop\csgo\csgo\"
      SET "_RootFolder=%~dp0"
      SET "CSGo_URL=!_RootFolder!Counter-Strike Global Offensive.url"
      SET "Music_File=!_RootFolder!csgomusic.m3u8"
    
      SET /A "_Timer_WinAmp_Start=9",   "_Timer_WinAmp_Kill= _Timer_WinAmp_Start + 240"
    
    )
    
    ECHO=%* | FIND /I ":Kill_Winamp" && (
      CALL :Kill_Winamp
    ) || (
      CALL :Main
    )
    
    ( ENDLOCAL
      Exit /b %_eLvl%
    }
    
    :Main
      COLOR 2F
      ECHO=======================================================================
      ECHO=  Launching CSGO, Waiting %_Timer_WinAmp_Start% seconds before starting Winamp.
      ECHO=======================================================================
      ECHO=
      "%CSGo_URL%"
      ECHO=
      SETLOCAL DisableDelayedExpansion
       %_StartKillCMD%
      ECHO=
      ECHO=Started Kill Timer..
      ECHO=
      Timeout %_Timer_WinAmp_Start%
      "%Music_File%"
      ECHO=Exiting, Remove the pause on the next line if not needed.
      Pause
    GOTO :EOF
    
    :Kill_Winamp
      COLOR 4F
      ECHO=======================================================================
      ECHO=  Waiting %_Timer_WinAmp_Kill% Seconds before Killing Winamp.
      ECHO=======================================================================
      ECHO=
      ECHO=
      Timeout %_Timer_WinAmp_Kill%
      Taskkill /IM winamp.exe
      ECHO=Exiting, Remove the pause on the next line if not needed.
      Pause
    GOTO :EOF