本文是本人初学bat脚本编写,如果有不妥,请指正。
脚本实现功能:需要将一个starter.bat脚本添加到计划任务,让开机启动自动执行starter.bat脚本,目前不确定该脚本存放路径,需要判断存在于C盘还是D盘,校验路径之后,将starter.bat脚本添加到计划任务中。脚本保存为ANSI格式,不然中文会出现乱码。
@echo off
set disk_c=C:\
set disk_d=D:\
set c_aps_path=%disk_c%aps\
set d_aps_path=%disk_d%aps\
set start_file_name=starter.bat
set delay_time=0003:00
rem 删除已存在的aps_boot的计划任务
schtasks /delete /tn aps_boot /f
rem // 当前脚本路径为
echo current dir is %~dp0
rem // 校验C盘是否存在
if exist %disk_c% (
echo %disk_c% is exist
rem echo 路径%c_aps_path%
if exist %c_aps_path% (
echo C盘aps路径存在
if exist %c_aps_path%%start_file_name% (
echo %c_aps_path%%start_file_name%脚本存在
schtasks /create /ru Users /tn aps_boot /sc onstart /tr %c_aps_path%%start_file_name% /delay %delay_time%
) else (
echo %c_aps_path%%start_file_name%脚本不存在
)
) else (
echo %c_aps_path%不存在
rem // 校验D盘是否存在
if exist %disk_d% (
echo %disk_d% is exist
if exist %d_aps_path% (
echo %d_aps_path%存在
if exist %d_aps_path%%start_file_name% (
echo %d_aps_path%%start_file_name%脚本存在
schtasks /create /ru Users /tn aps_boot /sc onstart /tr %d_aps_path%%start_file_name% /delay %delay_time%
) else (
echo %d_aps_path%%start_file_name%脚本不存在
)
) else (
echo %d_aps_path%不存在
)
) else (
echo %disk_d% is not exist
)
)
) else (
echo %disk_c% is not exist
rem // 校验D盘是否存在
if exist %disk_d% (
echo %disk_d% is exist
if exist %d_aps_path% (
echo C盘aps路径存在
if exist %d_aps_path%%start_file_name% (
echo %d_aps_path%%start_file_name%脚本存在
call %d_aps_path%%start_file_name%
) else (
echo %d_aps_path%%start_file_name%脚本不存在
)
) else (
echo %d_aps_path%不存在
)
) else (
echo %disk_d% is not exist
)
)
exit
