批处理+组策略 实现规定时间段无法开机and定时关机

某爱熬夜的人对付自己的东西

 

1、shutdown命令

shutdown -a  #取消现有的shutdown计划

shutdown -s -t [time]  #设定时间关机

shutdown -r -t [time]  #设定时间重启

 

2、bat基础

定义变量set

参数/p用于交互

参数/a用于指定等号右边的字符串为被评估的数字表达式

使用变量时需在前后均加上%

1 set /a t = 10000
2 echo %t%

用内置%time%获取时间

截取字符串 %变量名:~开始位置,结束位置%

 

3、其他的杂知识  goto  echo之类的

 

bat如下

1 if "%time:~,1%" equ " " if "%time:~1,1%" leq "5" goto shutdownNow
2 goto setShutdown
3 :shutdownNow
4 shutdown -s -t 0
5 goto end
6 :setShutdown
7 set /a t = (23 - %time:~,2%) * 3600 + (59 - %time:~3,2%) * 60 + (59 - %time:~6,2%)
8 shutdown -s -t %t%
9 :end
View Code

于是0点到6点不能使用电脑,其他时间自动设置到23:59:59(不知道为什么不是0点,再加一秒变成00:00:01)关机

 

 

把文件扔去%systemroot%\system32\grouppolicy\machine\scripts\Startup

然后win + r进gpedit.msc

computer configuration -> windows settings -> scripts(startup/shutdown) -> startup

把文件加进去就行了

 

 

然后还可以在批处理脚本里加上其他东西,比如

net share /del admin$

 

Done!

posted @ 2016-07-07 17:42  book丶book丶  阅读(1448)  评论(0编辑  收藏  举报