Open a PDF, then close it after 5 mins.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Cionn
Posts: 2
Joined: 10 Jul 2016 18:37

Open a PDF, then close it after 5 mins.

#1 Post by Cionn » 10 Jul 2016 18:55

Really appreciate a little help here.
The pdf is created from an excel sheet which gets updated regularly. However, if the pdf is left open, it will not get updated. So, I would like to put a bat file on the desktop instead of the shortcut to open the pdf file. Then after say 5 mins close the pdf. Therefore if someone forgets to close the pdf, it will close after 5 mins.
Any suggestions would be greatly appreciated.
Thank you
Cionn.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Open a PDF, then close it after 5 mins.

#2 Post by ShadowThief » 11 Jul 2016 00:17

Off the top of my head,

Code: Select all

@echo off
start "" "whatever_pdf_reader_you_use.exe pdf_file.pdf"
timeout /t 300
taskkill /F /IM whatever_pdf_reader_you_use.exe /T


Although if the batch file is closed, the PDF file will stay open.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Open a PDF, then close it after 5 mins.

#3 Post by foxidrive » 11 Jul 2016 11:06

ShadowThief wrote:Off the top of my head,


A small simplification and an extra switch.

Code: Select all

@echo off
start "" "pdf_file.pdf"
timeout /t 300 /nobreak
taskkill /F /IM whatever_pdf_reader_you_use.exe /T

Cionn
Posts: 2
Joined: 10 Jul 2016 18:37

Re: Open a PDF, then close it after 5 mins.

#4 Post by Cionn » 11 Jul 2016 18:58

Thank you ShadowThief & foxidrive for your help. If anyone is interested, here's my solution.

I created a bat file using ShadowThiefs code.
I found the /FI caused some problems but don't know why. So I tried just /F & it worked...

Code: Select all

@echo off
start "" "SomeDrive:\Somefolder\MyFile.pdf"
timeout /t 600
taskkill /F /IM AcroRd32.exe


This worked fine but the CMD window remains open for 600 secs.

So I created a vbs file to run the bat file...

Code: Select all

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "SomeDrive:\Somefolder\MyBatFile.bat" & Chr(34), 0
Set WshShell = Nothing


This works great, & the cmd file remains hidden. But I didn't like the icon, so I created a shortcut & changed its icon.

One other problem I encountered was the Windows Open File - Security Warning. This only happened when I created the files on my desktop, then pasted them to the appropriate folder. If I create the files in the appropriate folder, no security warning.

Thanks a lot for your help
Cionn.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Open a PDF, then close it after 5 mins.

#5 Post by foxidrive » 13 Jul 2016 19:20

Cionn wrote:One other problem I encountered was the Windows Open File - Security Warning. This only happened when I created the files on my desktop, then pasted them to the appropriate folder. If I create the files in the appropriate folder, no security warning.


Thanks for the feedback. I corrected the switch that you mentioned in the previous posts so future readers aren't easily misled.

The security warning may be from a permissions issue with the account you are using, or if the file is downloaded from a server then windows blocks the file until it is right clicked where you can find unblock in the properties.

Cionn wrote:I found the /FI caused some problems but don't know why. So I tried just /F & it worked...

FI is a filter switch that allows a choice of criteria when deciding which thing should be killed, and the F switch is used to force the program to close.

The force switch can corrupt data if the program has an open file, as the file is unceremoniously closed, but you are replacing the file so it is of no consequence. The force switch isn't needed for many programs as the program will behave normally and close in a quiet and usual way.

Post Reply