批处理文件...关闭openfiles

时间:2013-07-26 12:13:02

标签: pdf batch-file automation taskkill

我搜索了2天。现在我在这里,希望得到帮助。 我试图自动“杀死(关闭)”文件。 例如:

@echo off taskkill / IM Acrord32.exe

这很好用。唯一的问题是,它关闭每个PDF文件。但我只想关闭一个特定的文件。 也许通过路径。

所以,我希望任何人都可以帮助我。 (它不必是关闭此PDF文件的批处理脚本,它也可以是工具或其他东西)但它必须关闭文件AUTOMATICALLY。

我希望你理解我。我不是英国人。

到目前为止,谢谢。 M.L。

2 个答案:

答案 0 :(得分:0)

为此,您需要“告诉”Acrobat Reader关闭文件。但AFAIK Acrobat Reader不会公开任何用于远程控制的API。

我看到的唯一选择是将Ctrl + F4发送到Reader,但是无法从命令行(至少使用标准命令)。

答案 1 :(得分:0)

我不确切地知道你的意思,但是你要求一个脚本自动关闭Acrord32进程。我的脚本可以,但仅适用于已被“暂停”且处理器需求过多的进程。

因此无需对注册表,参数或设置Acrobat Reader进行任何更改。默认情况下编写的批处理脚本自动杀死进程Acrord32.exe并为此目的而设计,但该脚本可用于关闭任何其他进程过于繁琐的系统,当脚本调用相应的参数时被暂停。如果此参数包含带空格的长名称,则必须将参数括在引号中。例如,在脚本内部,可以确定几个参数的开头。暂停时间,重新检查时间或创建报告的位置(LOG)。脚本关闭所有进程满足任何用户的标准,当然,不是无法关闭的系统。可以在服务器上很有用,很多用户的工作。该脚本经过优化,以最大限度地减少自身负担。

谢谢

@echo off
REM Automatic closing Acrobat Reader or other process parameter specified in the call, which too much high the CPU
REM Preparing:  Artur Zgadzaj
REM ---------------------------------------------------------------------------------------------

SET REPEAT_TIME_VERIFICATION_[seconds]=7
SET IDLE_TIME_[seconds]=5

SET LOG_FOLDER=C:\UTIL\LOG



REM    # # # #      CHECKING OR IS STARTED AS ADMINISTRATOR     # # # # #

FSUTIL | findstr /I "volume" > nul&if not errorlevel 1  goto Administrator_OK

cls
echo ************************************
echo ***    RUN  AS  ADMINISTRATOR    ***
echo ************************************
echo.
echo.
echo Call up just as the Administrator. Abbreviation can be done to the script and set:
echo.
echo      Shortcut ^> Advanced ^> Run as Administrator
echo.
echo.
echo Alternatively, a single run "Run as Administrator"
echo or in the Schedule tasks with highest privileges
pause > nul
goto:eof
:Administrator_OK

SET WD=day
if "%~1"==""  (SET Close_Process=AcroRd32.exe)  else  (SET "Close_Process=%~1")
MD %LOG_FOLDER% 2>NUL
Setlocal EnableDelayedExpansion

:again
cls
echo Automatic closing %Close_Process%, which are charged to the processor too ...&echo.&echo.

FOR /F "tokens=2,7,8 delims=,"  %%A IN ('%SystemRoot%\System32\tasklist.exe /v /FO CSV^|find /I ^"%Close_Process%^"') DO (

  SET PROC=%%C
  SET PROC=!PROC:"=!

  FOR /F "tokens=2,3 delims=:"  %%s IN ("!PROC!") DO (SET PR=%%t
      if "!PR:~0,1!"=="0"  (SET /A PROC_TIME=%%s*60+!PR:~1,1!)  else  (SET /A PROC_TIME=%%s*60+!PR:~0,2!))

  if !PROC_TIME! GTR %IDLE_TIME_[seconds]%   (
      SET PID=%%A
      SET PID=!PID:"=!

      %SystemRoot%\system32\taskkill.exe /PID !PID! /F

      SET B=%%B
      SET B=!B:%USERDOMAIN%\=!
      SET B=!B:%COMPUTERNAME%\=!
      SET Process_User=!B:"=!

      if not "!DATE_WD!"=="%DATE%" ((FOR /F "tokens=1" %%W IN ('POWERSHELL GET-DATE -format dddd') DO SET WD=%%W)&&SET DATE_WD=%DATE%)
      echo %TIME:~0,8%    ^(Hanging:  !PROC:~-5!^)         !Process_User! >>"%LOG_FOLDER%\%DATE:-=.%  ^(!WD:~0,3!^)  Close_%Close_Process%.TXT"
      )
  )

TIMEOUT /T %REPEAT_TIME_VERIFICATION_[seconds]% > nul
goto again
相关问题