title: Using batch to close open image file or word doc
body: <p>I am coding a choose your own adventure game. Im at the point where a player would have a choice to look at a poster or a document on a desk and the game would open a .jpg file with the poster art or document on the desk i then want the game to close the .jpg file after 5 seconds. I have found so many questions about how to close programs and .exe with batch using exit/b and taskill but there is nothing about closing specific open files viewed by a program like an image viewer. In my case, the .jpg is being opened using windows photo viewer. the title of the window is "BADGE.jpg - Windows Photo Viewer" if i could and when the game is played on another computer there might be a different default image viewer, so i need a way just to close the file regardless of what program has it open.</p>
  
  <p>below is a snippet of my code. :Test1 is where my problem lies</p>
  
  <pre class="lang-bat prettyprint-override"><code>@ECHO OFF
  : START
  CLS
  ECHO THIS IS A TEST PROGRAM TO SHOW THE USER AN IMAGE 
  ECHO OR FILE AND THEN CLOSE AFTER 5 SECONDS
  PAUSE &gt;NUL
  GOTO TEST1
  
  : TEST1 
  ECHO PRESS ENTER TO OPEN IMAGE
  ECHO.
  PAUSE 
  START "" "%~dp0\BADGE.jpg" 
  PING -n 2 0.0.0.0 1&gt;NUL
  exit "%~dp0\BADGE.jpg" 
  :: TASKKILL /F /IM BADGE.jpg
  PAUSE
  goto end
  
  
  : end
  echo.
  echo IF THE IMAGE CLOSED AFTER 5 SECONDS THEN THIS TEST WAS A SUCCESSFUL
  PAUSE
  GOTO START
  </code></pre>