Solved

Close Adobe Reader Automatically After Print MS DOS Command Script

Posted on 2011-02-16
18
8,117 Views
Last Modified: 2012-05-11
Hi All,

I have a command script that performs the following tasks:

1. Opens a PDF File on a server
2. Prints it
3. Renames the file
4. Loops to the next file

I am having a problem getting the script to close adobe reader after it has finished.

Could someone please help?

CF

@echo off

REM Define paths and settings for script
set DOCFullPath=\\nyenad03fs002\share\Replenishment\DAILY
set Acrobat=C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe

REM Build time stamp to add to end of the files processed (YYYYMMDD_HHMMSS)
set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

REM Process all files within the folder that have not already been processed
for /F "tokens=*" %%A in ('dir /a-d /b "%DOCFullPath%\*.pdf" ^| find /i /v "_PRINTED_"') do (

  REM Print document
  "%Acrobat%" /n /s /o /h /t "%DOCFullPath%\%%A" "%Printer%" "RICOH Aficio MP 3500 PCL 6" "NPSO01B4PRMFDCOL"

  REM Rename file to indicate processed
  ren "%DOCFullPath%\%%A" "%%~nA_PRINTED_%Stamp%.pdf"

  REM End the PDF print program (doesn't close on its own after printing)
  taskkill /IM AcroRd32.exe
)

EXIT

Open in new window

0
Comment
Question by:creativefusion
  • 8
  • 5
  • 3
  • +2
18 Comments
 
LVL 7

Expert Comment

by:Waseems
ID: 34912292
taskkill should do the trick but make sure process name in task manager as AcroRd32.exe if not change it in the script if name is correct add /F to the line
0
 

Author Comment

by:creativefusion
ID: 34912411
Hi

I checked my task manager and it is showing AcroRd32.exe which is correct.

Where should I add the /F to the line?

REM End the PDF print program (doesn't close on its own after printing)
  taskkill /IM AcroRd32.exe
)

CF
0
 
LVL 5

Assisted Solution

by:jason987
jason987 earned 25 total points
ID: 34912428
taskkill /F /IM AcroRd32.exe
0
 

Author Comment

by:creativefusion
ID: 34912526
ERROR: The process "AcroRd32.exe" not found

I copied the script as is for review..
@echo off

REM Define paths and settings for script
set DOCFullPath=\\nyenad03fs002\share\Replenishment\DAILY
set Acrobat=C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe

REM Build time stamp to add to end of the files processed (YYYYMMDD_HHMMSS)
set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

REM Process all files within the folder that have not already been processed
for /F "tokens=*" %%A in ('dir /a-d /b "%DOCFullPath%\*.pdf" ^| find /i /v "_PRINTED_"') do (

  REM Print document
  "%Acrobat%" /n /s /o /h /t "%DOCFullPath%\%%A" "%Printer%" "RICOH Aficio MP 3500 PCL 6" "NPSO01B4PRMFDCOL"

  REM Rename file to indicate processed
  ren "%DOCFullPath%\%%A" "%%~nA_PRINTED_%Stamp%.pdf"

  REM End the PDF print program (doesn't close on its own after printing)
  taskkill /F /IM AcroRd32.exe 
)

EXIT

Open in new window

0
 
LVL 7

Expert Comment

by:Waseems
ID: 34912988
if command is run out of script, does it work
 taskkill /F /IM AcroRd32.exe
0
 
LVL 7

Assisted Solution

by:Waseems
Waseems earned 150 total points
ID: 34913014
if command run when you run it manual, I think script is reaching to end processes before it actually started try adding start /w before running acrobat
so line 14 will be
"Start /w %Acrobat%" /n /s /o /h /t "%DOCFullPath%\%%A" "%Printer%" "RICOH Aficio MP 3500 PCL 6" "NPSO01B4PRMFDCOL"
0
 

Author Comment

by:creativefusion
ID: 34913185
Hi Waseem,

Yes it does work when it is out of the script.

CF
0
 

Author Comment

by:creativefusion
ID: 34913222
I inserted your previous but now it does not even start the reader or open the documents...

Code enclosed >-

@echo off

REM Define paths and settings for script
set DOCFullPath=\\nyenad03fs002\share\Replenishment\DAILY
set Acrobat=C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe

set PrtName=NPSOGFD4PRMFDCOL
set PrtDriverName="RICOH Aficio MP C3500 PCL 6"
set PrtPort=EQ_NPSOGFD4PRMFDCOL

REM Build time stamp to add to end of the files processed (YYYYMMDD_HHMMSS)
set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

REM Process all files within the folder that have not already been processed
for /F "tokens=*" %%A in ('dir /a-d /b "%DOCFullPath%\*.pdf" ^| find /i /v "_PRINTED_"') do (

  REM Print document
  Start/w"%Acrobat%" /n /s /o /h /t "%DOCFullPath%\%%A" "%PrtName%" "%PrtDriverName%" "%PrtPort%"

  REM Rename file to indicate processed
  ren "%DOCFullPath%\%%A" "%%~nA_PRINTED_%Stamp%.pdf"

  REM End the PDF print program (doesn't close on its own after printing)
  taskkill /F /IM AcroRd32.exe
)

EXIT

Open in new window

0
 
LVL 7

Expert Comment

by:Waseems
ID: 34913461
try this
@echo off

REM Define paths and settings for script
set DOCFullPath=\\nyenad03fs002\share\Replenishment\DAILY
set Acrobat=C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe

set PrtName=NPSOGFD4PRMFDCOL
set PrtDriverName="RICOH Aficio MP C3500 PCL 6"
set PrtPort=EQ_NPSOGFD4PRMFDCOL

REM Build time stamp to add to end of the files processed (YYYYMMDD_HHMMSS)
set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

REM Process all files within the folder that have not already been processed
for /F "tokens=*" %%A in ('dir /a-d /b "%DOCFullPath%\*.pdf" ^| find /i /v "_PRINTED_"') do (

  REM Print document
  "cmd /k Start/w %Acrobat%" /n /s /o /h /t "%DOCFullPath%\%%A" "%PrtName%" "%PrtDriverName%" "%PrtPort%"

  REM Rename file to indicate processed
  ren "%DOCFullPath%\%%A" "%%~nA_PRINTED_%Stamp%.pdf"

  REM End the PDF print program (doesn't close on its own after printing)
  taskkill /F /IM AcroRd32.exe
)

EXIT

Open in new window

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:creativefusion
ID: 34913539
Hi,

I ran it and got the following windows error:

Window cannot find 'C:\Program'. Makke sure you typed the name.....

CF
0
 
LVL 7

Expert Comment

by:Waseems
ID: 34915023
I am sorry it is only the location of "
@echo off

REM Define paths and settings for script
set DOCFullPath=\\nyenad03fs002\share\Replenishment\DAILY
set Acrobat=C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe

set PrtName=NPSOGFD4PRMFDCOL
set PrtDriverName="RICOH Aficio MP C3500 PCL 6"
set PrtPort=EQ_NPSOGFD4PRMFDCOL

REM Build time stamp to add to end of the files processed (YYYYMMDD_HHMMSS)
set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

REM Process all files within the folder that have not already been processed
for /F "tokens=*" %%A in ('dir /a-d /b "%DOCFullPath%\*.pdf" ^| find /i /v "_PRINTED_"') do (

  REM Print document
  cmd /k Start /w "%Acrobat%" /n /s /o /h /t "%DOCFullPath%\%%A" "%PrtName%" "%PrtDriverName%" "%PrtPort%"

  REM Rename file to indicate processed
  ren "%DOCFullPath%\%%A" "%%~nA_PRINTED_%Stamp%.pdf"

  REM End the PDF print program (doesn't close on its own after printing)
  taskkill /F /IM AcroRd32.exe
)

EXIT

Open in new window

0
 
LVL 14

Expert Comment

by:Don Thomson
ID: 34944247
Try CALL taskkill  /F /IM acroRD32.exe

I just tried it using outlook.exe and as long as my case was upper case for the /IM and for the OUTLOOK.EXE  is works

Look under task manager Processes for the uppper/lower case of AcroRd32.exe  

0
 
LVL 14

Expert Comment

by:Don Thomson
ID: 34944336
Sorry - It worked but only if you put the Call taskkill /M /IM AcroRd32.exe in twice
Don't ask me why but putting the line in a second time works every time
0
 
LVL 51

Assisted Solution

by:Bill Prew
Bill Prew earned 25 total points
ID: 34945335
You might try putting a small delay in front of the taskkill line, with something like:

ping 1.1.1.1 -n 1 -w 2000>NUL

That will add a 2 second delay before trying to kill the program.  Just in case it is in a state it can't be killed right after it returns control to the BAT script.

~bp
0
 

Author Comment

by:creativefusion
ID: 34985123
@ All,

Sorry for the delay in response on this one, I have been away on holiday.

@ DTH

Thanks for the advice.

I have not seen the example of adding the task kill twice before. Can you tell me exactly how this should look in the script?

Enclosed in current format.

Thanks
@echo off

REM Define paths and settings for script
set DOCFullPath=\\nyenad03fs002\share\Replenishment\DAILY
set Acrobat=C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe

set PrtName=NPSOGFD4PRMFDCOL
set PrtDriverName="RICOH Aficio MP C3500 PCL 6"
set PrtPort=EQ_NPSOGFD4PRMFDCOL

REM Build time stamp to add to end of the files processed (YYYYMMDD_HHMMSS)
set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

REM Process all files within the folder that have not already been processed
for /F "tokens=*" %%A in ('dir /a-d /b "%DOCFullPath%\*.pdf" ^| find /i /v "_PRINTED_"') do (

  REM Print document
  cmd /k Start /w "%Acrobat%" /n /s /o /h /t "%DOCFullPath%\%%A" "%PrtName%" "%PrtDriverName%" "%PrtPort%"

  REM Rename file to indicate processed
  ren "%DOCFullPath%\%%A" "%%~nA_PRINTED_%Stamp%.pdf"
  
  'adding a 2 second delay so to give time for the application to print the document
  ping 1.1.1.1 -n 1 -w 2000>NUL

	
  REM End the PDF print program (doesn't close on its own after printing)
  taskkill /F /IM AcroRd32.exe
)

EXIT

Open in new window

0
 

Author Comment

by:creativefusion
ID: 34985131
Woops. Sorry DTHl, I added a vb comment line instead of a REM statement. My bad, you can tell I've been away for a while!!!


@echo off

REM Define paths and settings for script
set DOCFullPath=\\nyenad03fs002\share\Replenishment\DAILY
set Acrobat=C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe

set PrtName=NPSOGFD4PRMFDCOL
set PrtDriverName="RICOH Aficio MP C3500 PCL 6"
set PrtPort=EQ_NPSOGFD4PRMFDCOL

REM Build time stamp to add to end of the files processed (YYYYMMDD_HHMMSS)
set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

REM Process all files within the folder that have not already been processed
for /F "tokens=*" %%A in ('dir /a-d /b "%DOCFullPath%\*.pdf" ^| find /i /v "_PRINTED_"') do (

  REM Print document
  cmd /k Start /w "%Acrobat%" /n /s /o /h /t "%DOCFullPath%\%%A" "%PrtName%" "%PrtDriverName%" "%PrtPort%"

  REM Rename file to indicate processed
  ren "%DOCFullPath%\%%A" "%%~nA_PRINTED_%Stamp%.pdf"
  
  REM adding a 2 second delay so to give time for the application to print the document
  ping 1.1.1.1 -n 1 -w 2000>NUL
	
  REM End the PDF print program as it doesn't close on its own after printing
  taskkill /F /IM AcroRd32.exe
)

EXIT

Open in new window

0
 
LVL 14

Accepted Solution

by:
Don Thomson earned 300 total points
ID: 34986729
rem    This is what I did
rem  I just ran the taskkill command twice - that seemed to work



@echo off

REM Define paths and settings for script
set DOCFullPath=\\nyenad03fs002\share\Replenishment\DAILY
set Acrobat=C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe

set PrtName=NPSOGFD4PRMFDCOL
set PrtDriverName="RICOH Aficio MP C3500 PCL 6"
set PrtPort=EQ_NPSOGFD4PRMFDCOL

REM Build time stamp to add to end of the files processed (YYYYMMDD_HHMMSS)
set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%

REM Process all files within the folder that have not already been processed
for /F "tokens=*" %%A in ('dir /a-d /b "%DOCFullPath%\*.pdf" ^| find /i /v "_PRINTED_"') do (

  REM Print document
  cmd /k Start /w "%Acrobat%" /n /s /o /h /t "%DOCFullPath%\%%A" "%PrtName%" "%PrtDriverName%" "%PrtPort%"

  REM Rename file to indicate processed
  ren "%DOCFullPath%\%%A" "%%~nA_PRINTED_%Stamp%.pdf"
 
  REM adding a 2 second delay so to give time for the application to print the document
  ping 1.1.1.1 -n 1 -w 2000>NUL
      
  REM End the PDF print program as it doesn't close on its own after printing
  taskkill /F /IM AcroRd32.exe
  taskkill /F /IM AcroRd32.exe
)

EXIT
0
 

Author Closing Comment

by:creativefusion
ID: 34986893
Excellent outcome.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now