Link to home
Start Free TrialLog in
Avatar of creativefusion
creativefusionFlag for Australia

asked on

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

Avatar of Waseems
Waseems
Flag of Syrian Arab Republic image

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
Avatar of creativefusion

ASKER

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
SOLUTION
Avatar of jason987
jason987

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

if command is run out of script, does it work
 taskkill /F /IM AcroRd32.exe
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Waseem,

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

CF
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

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

Hi,

I ran it and got the following windows error:

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

CF
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

Avatar of Don Thomson
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  

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@ 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

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

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent outcome.