Diablo – Run task when Diablo II is closed

diablo-2windows 7

Many old games (Starcraft, Diablo II, Diablo, Age of Kings…) have huge problems displaying colors correctly on Windows 7. For Starcraft, I have succeeded to fix this using:

  1. Opening the screen resolution settings dialog (sometimes works)
  2. Killing explorer.exe (always works)
  3. Using DirectDraw color fix (sometimes works)

For Diablo II, only the 2) works for me. So I have written following batch file:

rem Kill explorer.exe
taskkill /IM explorer.exe /F
rem Run the game
"Diablo II.exe"
rem After game is over, resume explorer.exe
rem explorer.exe

The problem is, that the actual process for the game is Game.exe and the Diablo II.exe exits immediately – so the explorer immediately restarts.

Do you have any idea, how to automate the resuming of explorer.exe after I close Diablo II?

Best Answer

You can write a loop that checks if a specific process (e.g. "Game.exe") is running and repeats checking until it is closed. The code could look like this.

rem Kill explorer.exe
taskkill /IM explorer.exe /F
"Diablo II.exe"
rem Wait 5 seconds for Game.exe to start. Must be tweaked.
timeout /T 5 /NOBREAK > NUL
:whilegameruns
rem Check if Game.exe is running
tasklist /FI "IMAGENAME eq Game.exe" 2>NUL | find /I /N 

"Game.exe">NUL
if "%ERRORLEVEL%"=="0" (
    rem Sleep for 5 seconds
    timeout /T 5 /NOBREAK > NUL
    goto :whilegameruns
)
rem Run explorer.exe afterwards
"explorer.exe"

As I do now have Diablo 2 handy this code is not tested properly. Depending on the flavor of Windows the commands might need to be changed slightly.