求一个BAT命令

AdmiralMeng 2010-07-05 11:56:29
想用DOS批处理实现关机,开机自动运行批处理。判断如果当前时间大于22:30则马上关机,如果小于22:30则设定关机时间为22:30.

原理:
if (now() > 22:30)
{
shutdown();
}
else
{
setshutdowntime(22:30);
}

请教这个换成批处理该怎么写?

我知道以下几个命令:
shutdown() =========> Shutdown.exe -s -t 60 延时60秒关机
setshutdowntime(22:30) =========> at 22:30 Shutdown -s 22:30定时关机

请问整个代码怎么写?
...全文
63 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangfashi 2010-07-07
  • 打赏
  • 举报
回复
呵呵。
coolwolf1941 2010-07-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 just4 的回复:]
BatchFile code
@echo off
rem 测试下
set /a "time1=%time:~0,2%*60+%time:~3,2%"
set /a "time2=22*60+30"
if %time1% gtr %time2% shutdown /s /t 60 /f
else at 22:30 "shutdown /s /t 60 /f"
rem 何必如此,直接如下……
[/Quote]

精辟
xiaobaomeng 2010-07-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ljc007 的回复:]
赞同,一句话即可。
at /every:m,t,w,th,f,s,su 22:30 "shutdown /s /t 0 /f"
[/Quote]
简洁
ljc007 2010-07-06
  • 打赏
  • 举报
回复
赞同,一句话即可。
at /every:m,t,w,th,f,s,su 22:30 "shutdown /s /t 0 /f"
就是just4 2010-07-06
  • 打赏
  • 举报
回复
[code=BatchFile]@echo off
rem 测试下
set /a "time1=%time:~0,2%*60+%time:~3,2%"
set /a "time2=22*60+30"
if %time1% gtr %time2% shutdown /s /t 60 /f
else at 22:30 "shutdown /s /t 60 /f"
rem 何必如此,直接如下不行么?
at /every:m,t,w,th,f,s,su 22:30 "shutdown /s /t 0 /f"[/code]

6,850

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧