本帖最后由 yhcfsr 于 2018-5-24 18:14 编辑
以优酷为例,按需改第2,3行;输出文件路径改第11行:- @echo off
- set "task=youku"
- set "prog_path=E:\APP\YouKu\YoukuClient\Youku.exe"
- set "start_times=0"
- :begin
- set "find_task="&set "event_record="
- for /f "delims= " %%a in ('tasklist^|findstr /i /r "%task%"') do set "find_task=true"
- if not defined find_task (start "" "%prog_path%"&set/a start_times+=1)
- if not defined find_task (set "event_record=%date%%time% ;启动第%start_times%次")
- if defined event_record (echo;%event_record%)
- if defined event_record (echo;%event_record%)>>"event.log"
- timeout /t 600 /nobreak
- goto:begin
复制代码 第二种方案,用以下脚本启动程序,程序运行中,脚本暂停扫描;一旦进程中止,立即启动程序,不会有延时。
无论从资源占用还是程序功能,这种方案比第一种都要有优势。- @echo off
- set "task=youku"
- set "prog_path=E:\APP\YouKu\YoukuClient\Youku.exe"
- set "start_times=0"
- :begin
- set "start_record="
- tasklist|findstr /ri "%task%"||(
- set/a "start_times+=1"&setlocal enabledelayedexpansion
- set "start_record=%date%%time%;启动!start_times!次"
- echo;!start_record!
- echo;!start_record!>>envent.log
- endlocal
- "%prog_path%"
- )
- goto:begin
复制代码
|