How to use batch files to launch programs and close YzDock

UPDATE: Since the advent of RocketDock there doesn't seem much need for YzDock anymore. It doesn't intefere with full screen programs for a start! But if you still prefer YzDock, read on...

Well hello! This is a quick page with information about how to use batch files to launch programs from YzDock (or indeed anything else), close it, and then once the program is finished, re-launch YzDock. This is especially useful for full screen games which alt-tab back to windows whenever you move the mouse to where you YzDock is running.
NOTE: I cannot get you a copy of YzDock.

Gyphie's Executor

Gyphie wrote a clever little batch file to do almost everything that you need. It has one minor failing which I will detail after, but other than that you're good to go. Just paste it into notepad, save that as 'runprogram.bat' (or whatever) in your YzDock folder, and follow the instructions:

@echo off
rem ** By Gyphie June 2003. YzDock game executor.  Kill YzDock. Runs the program. Once the program
rem ** is finished restart YzDock.

       if '%1' == '' goto instructions
       if '%2' == '' goto instructions
       goto execute


:execute
       SET dopause=0
       
       :processargs
               if '%3' == 'pause' SET dopause=1
       
               if NOT '%3' == 'pause' SET params=%params%%3%
 
               shift /3
               if NOT '%3' == '' GOTO processargs
 
       echo Thanks for using Gyphie's Executor....
       echo.
       echo Ending YzDock...
       taskkill /F /IM YzDock.exe > nul
       
       echo Starting %1\%2 %params%...
       start "Gyphies Executor" /WAIT /D%1 %2 %params%
       
       if '%dopause%' == '1' goto dopause
       goto restart
:dopause
       pause
       goto restart


:restart        
       echo Restarting YzDock...
       start "Y'z Dock" /D"D:\Program Files\yzdck" yzdock.exe
       goto end
       
       
:instructions
       cls
       echo.
       echo.
       echo Gyphie's Executor
       echo ********************************************************************************
       echo READ ALL THE INSTRUCTIONS they give useful info on all the options you have.
       echo.
       echo The idea behind this batch file is to have ONE batch file for all your games.
       echo Instead of putting the game exe in the "Link To:" field use this batch file
       echo then put the game information in the 'Arguments:" field as described below.
       echo.
       echo Usage:  runprogram.bat "FILE PATH" "FILE NAME" [PARAMETERS] [pause]
       echo.
       echo Installation:
       echo Place a copy of this batch file in the YzDock folder and make a new dock item.
       echo Here is an example of what you might enter for the Dock Item Settings.
       echo.
       echo  Name:         Gyphie 3D 2003
       echo  Link to:      c:\Program Files\YzDock\runprogram.bat
       echo  Arguments:    "c:\games\Gyphie 3D 2003" "Gyphie 3D 2003.exe" -d games -b pause
       echo  Work Folder:  c:\games\Unreal II
       echo  Show Command: Minimized
       echo.
       echo ********************************************************************************
       pause
       cls
       echo Usage:
       echo File Path:
       echo   The Folder where your program is located.  If there are any spaces in in the
       echo   names you MUST put it in Quotes:  "C:\Program Files\Gyphie 3D 2003"
       echo   It is also important NOT to put a '\' and the end of the File Path. For
       echo   example "c:\Program Files\Gyphie 3D 2003\" will not work because there is
       echo   a '\' at the end. It should be "c:\Program Files\Gyphie 3D 2003" to
       echo   work correctly.
       echo.
       echo File Name:
       echo   The name of the file you want to run.  If there are any spaces in the name
       echo   you MUST put it in Quotes: "Red Faction.exe"
       echo.
       echo Parameters:
       echo   Any parameters you want to send to your game (e.g. to load a MOD in Quake).
       echo   You probably should not put these in quotes unless you would for your game.
       echo.
       echo Continue...
       pause
       echo Pause:
       echo   Use the 'pause' parameter to make the batch file pause before opening
       echo   Y'z Dock. Many games use loaders (a little screen that has a "Start Game"
       echo   button) and the batch file cannot tell the difference between the loader
       echo   and the game.
       echo      Putting the 'pause' parameter causes the batch file to wait for you to press a
       echo   key before reloading Y'z Dock so it doesn't get reloaded before the game begins.
       echo.
       echo   The word 'pause' must be lowercase.
       echo.
       echo END OF INSTRUCTIONS
       pause
       goto end

:end
       SET params=0
       SET dopause=0
       SET params=
       SET dopause=
exit

Multiple parameters

Unfortunately, Gyphie's executor doesn't seem to handle multiple command line parameters too well. Say you wanted to run Game.exe with the parameters -w 1280 -h 1024. If you used that batch file it would fire them off as -w 1280-h 1024 (ie, no space), which means your program won't parse them properly. There's probably a way of improving the batch file to fix this, but I don't know how (anyone?). However, I do know how to hard code a batch file to run a specific game with multiple parameters:

@echo off
       goto execute


:execute
       SET dopause=0
       
       echo Thanks for using Gyphie's Executor....
       echo.
       echo Ending YzDock...
       taskkill /F /IM YzDock.exe > nul
       
       echo Starting Homeworld2...
       start "Executor" /WAIT /D"D:\Games\Homeworld2\Bin\Release" Homeworld2.exe -w 1280 -h 1024
       
       if '%dopause%' == '1' goto dopause
       goto restart
:dopause
       pause
       goto restart


:restart        
       echo Restarting YzDock...
       start "Y'z Dock" /D"D:\Program Files\yzdck" yzdock.exe
       goto end
  
  
:end
       SET dopause=0
       SET dopause=
exit

I followed Gryphie's format so hopefully you know where you are. Just paste this into notepad, save as a .bat in your YzDock folder, and edit the game path and parameters to suit. Remember that if your program has some kind of splash screen (most modern games do) before it starts proper, then you'll need to change that SET dopause=0 to SET dopause=1 to stop it restarting YzDock prematurely. Also, rather than messing about with the shortcut as with Gyphie's script, you just run the .bat and it all should work. Obviously it's not as flexible, though, as you have to make a new .bat for every game.

Bonus tip:

Possibly a bit obvious, but if you're fed up with losing your nice looking shortcuts whenever you use one of these .bats, you can of course right-click on the shortcut, change icon, and browse to the games folder and find the right icon there (usually within the main .exe).

That's all!
Cheers, Chris