• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 11192
  • Last Modified:

Close Adobe Reader Automatically After Print MS DOS Command Script

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
creativefusion
Asked:
creativefusion
  • 8
  • 5
  • 3
  • +2
4 Solutions
 
WaseemsCommented:
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
 
creativefusionAuthor Commented:
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
 
jason987Commented:
taskkill /F /IM AcroRd32.exe
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
creativefusionAuthor Commented:
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
 
WaseemsCommented:
if command is run out of script, does it work
 taskkill /F /IM AcroRd32.exe
0
 
WaseemsCommented:
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
 
creativefusionAuthor Commented:
Hi Waseem,

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

CF
0
 
creativefusionAuthor Commented:
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
 
WaseemsCommented:
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
 
creativefusionAuthor Commented:
Hi,

I ran it and got the following windows error:

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

CF
0
 
WaseemsCommented:
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
 
Don ThomsonCommented:
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
 
Don ThomsonCommented:
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
 
Bill PrewCommented:
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
 
creativefusionAuthor Commented:
@ 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
 
creativefusionAuthor Commented:
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
 
Don ThomsonCommented:
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
 
creativefusionAuthor Commented:
Excellent outcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 8
  • 5
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now