天天看点

DOS定时执行指定命令然后关闭计算机批处理代码

DOS定时执行指定命令然后关闭计算机批处理代码

@echo off 
:ag 
set t= 5:51
@REM t为你设置的时间
if %t%==%time:~0,5% goto word
goto ag 
:word 
cd d:
d:
dir>test.txt
shutdown -s -t 10
           

说明:

echo off 表示,这条命令之后的都不会在命令串口显示(指命令,而不是指输出,输出还是正常的)

:ag :word 这个是程序标签 相当于其他语言中的函数名称(有点不完全,但可以这么认为)

set 设置定时开始运行的时间。

REM 是注释

%t% 变量表示方法吧,可以这么理解

%time:~0,5%   时间格式,只显示5位( 其中0 便是从第几位开始显示 5表示显示位数的总数 负数的话,相反,为总位数减去这个数。)

注意“ 5:51”  前面有一个空格,对于小于10点的,注意加空格,大于等于10点的,不要空格,刚好5位,如:“22:10”

goto 跳转语句,当条件成立时(if %t%==%time:~0,5% goto word),跳转到 :word

开始执行

cd d:

d:

dir>test.txt

最后执行关机指令(shutdown -s -t 10)

文章参考链接:

https://blog.csdn.net/wolinxuebin/article/details/7830335

https://blog.csdn.net/wangzhpwang/article/details/52679687

https://blog.csdn.net/lanpiao_87/article/details/7799616

https://blog.csdn.net/baidu_26408419/article/details/78885206

(windows下.bat每隔一段时间(例如15分钟)运行一次某python文件)

https://blog.csdn.net/huryer/article/details/52702832

https://blog.csdn.net/wangzhpwang/article/details/44342225

https://blog.csdn.net/mighty13/article/details/78110676