Solved

Close Adobe Reader Automatically After Print MS DOS Command Script

Posted on 2011-02-16
18
8,463 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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
 

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 53

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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