返回列表 发帖

[系统相关] [已解决]根据冬天、夏天作息时间,自动关机。为啥只有17:28到17:29无法关机??

本帖最后由 ygqiang 于 2015-10-19 19:46 编辑

[已解决]根据冬天、夏天作息时间,自动关机。为啥只有17:28到17:29无法关机??

请直接看16楼的问题。。。谢谢。。。

代码已经修改成正确的。。
@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("%~fs0 h",0)(window.close)&&exit
:begin
rem 下边开始写批处代码了
————————————————————————————————————————————————
:first1-2
set "t=%time: =0%"
if "%t:~,5%" geq "11:27" if "%t:~,5%" leq "11:29" goto :first11
if "%t:~,5%" geq "21:50" if "%t:~,5%" leq "21:55" goto :first11
—————————————————————————
set "tim=%date:~5,2%"
if %tim% geq 01 if %tim% leq 04 goto :firstd
if %tim% geq 10 if %tim% leq 12 goto :firstd
if %tim% geq 05 if %tim% leq 09 goto :firstx
—————————————————————————
goto :firstx
—————————————————————————
:firstd
if "%t:~,5%" geq "17:28" if "%t:~,5%" leq "17:29" goto :first11
goto :firstn
:firstx
if "%t:~,5%" geq "17:58" if "%t:~,5%" leq "17:59" goto :first11
—————————————————————————
:firstn
ping 127.0.0.1 -n 40 >nul 2>nul
goto :first1-2
———————————————————————
:first11
ping 127.0.0.1 -n 5 >nul 2>nul
:Main
@Echo off
cls
;瞬间清理进程
REM 系统进程
Echo.audiodg.exe>>c:\Server1.ini
Echo.cmd.exe>>c:\Server1.ini
Echo.conhost.exe>>c:\Server1.ini
Echo.csrss.exe>>c:\Server1.ini
Echo.dllhost.exe>>c:\Server1.ini
Echo.dwm.exe>>c:\Server1.ini
Echo.explorer.exe>>c:\Server1.ini
Echo.lsass.exe>>c:\Server1.ini
Echo.lsm.exe>>c:\Server1.ini
Echo.MacTray.exe>>c:\Server1.ini
Echo.services.exe>>c:\Server1.ini
Echo.smss.exe>>c:\Server1.ini
Echo.svchost.exe>>c:\Server1.ini
Echo.taskhost.exe>>c:\Server1.ini
Echo.tasklist.exe>>c:\Server1.ini
Echo.wininit.exe>>c:\Server1.ini
Echo.winlogon.exe>>c:\Server1.ini
Echo.WmiPrvSE.exe>>c:\Server1.ini
Tasklist.exe>c:\Exelist1.txt
FOR /F "skip=5" %%i in (c:\Exelist1.txt) do call :Cmpexe %%i
DEL /F /Q c:\Server1.ini >Nul 2>Nul
DEL /F /Q c:\Exelist1.txt >Nul 2>Nul
ping 127.0.0.1 -n 2 >nul 2>nul
shutdown.exe -s -t 3
Echo. & Echo.结束,任意键再次执行。 & Pause >Nul & Goto Main
:Cmpexe
        FOR /F %%i IN (c:\Server1.ini) DO IF %*==%%i Goto :END
        REM Echo. & Echo.任意键清理 %*
        REM Pause >Nul
        Taskkill.exe -IM %** -F
:ENDCOPY

回复  ygqiang
看你开头部分 0开头的数字比较也不是很牢靠哦
terse 发表于 2015-10-19 02:01
set "tim=%date:~5,2%"
if %tim% geq 01 if %tim% leq 04 goto :firstd
if %tim% geq 10 if %tim% leq 12 goto :firstd
if %tim% geq 05 if %tim% leq 09 goto :firstxCOPY
xp系统下。特意测试过了。。这个代码好用。。。

TOP

回复 20# ygqiang
看你开头部分 0开头的数字比较也不是很牢靠哦

TOP

本帖最后由 CrLf 于 2015-10-18 19:13 编辑

回复 23# 依山居


    问题是我印象中 32 位 win7 里的 schtasks 好像还没这个功能,64 位 win7 却有,本以为两个版本的系统应该只有位数上的区别…不知道是后来更新了还是我记错了

TOP

回复 13# CrLf


    不同系统带的schtasks 版本不一样,支持的功能也不完全一样。

TOP

回复 15# ygqiang
代码是否直观与应用是两种问题,代码在直观错误执行后要直观有什么作用?
写代码完全取决于作者的个人习惯;
你的IF判断是利用了判断字符串的大小进行对比的,而我用的是判断数字进行对比的,两者对比结果数字更有优越性,本来想分开写的考虑到你的代码是每行执行特意合并成了一行
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

TOP

回复 20# ygqiang


    设置date time变量为有疑问的时间点,并将代码中的shutdown加上echo,运行后能显示shutdown命令就对了

TOP

本帖最后由 ygqiang 于 2015-10-18 17:24 编辑

回复 19# CrLf


    回复 18# terse

这个代码,应该没问题了吧?谢谢
:firsta
—————————————————————————
set "tim=%date:~5,2%"
if %tim% geq 01 if %tim% leq 04 goto :firstd
if %tim% geq 10 if %tim% leq 12 goto :firstd
if %tim% geq 05 if %tim% leq 09 goto :firstx
—————————————————————————
goto :firstx
—————————————————————————
:firstd
if "%t:~,5%" geq "17:28" if "%t:~,5%" leq "17:29" goto :first11
goto :firstn
:firstx
if "%t:~,5%" geq "17:58" if "%t:~,5%" leq "17:59" goto :first11
—————————————————————————
:firstn
ping 127.0.0.1 -n 40 >nul 2>nul
goto :firsta
———————————————————————
:first11
ping 127.0.0.1 -n 5 >nul 2>nul
shutdown.exe -s -t 3COPY

TOP

楼上的意思是这样:
if %tim% geq 10COPY
if "%tim%" geq "10"COPY

TOP

回复 17# ygqiang
去掉引号

TOP

顶下。。。。。

TOP

批处理判断月份。现在是10月份,geq表示大于等于,为啥没有跳转呢?

批处理判断月份。现在是10月份,geq表示大于等于,为啥没有跳转呢?
@echo off
set "t=%time: =0%"
if "%t:~,5%" geq "11:27" if "%t:~,5%" leq "11:29" goto :first11
if "%t:~,5%" geq "21:50" if "%t:~,5%" leq "21:55" goto :first11
set "tim=%date:~5,2%"
echo %tim%
if %tim% geq "10" if %tim% leq "12" goto :firstd
echo 0000
pause
exit
:firstd
echo 10000
pause
exitCOPY
附件: 您需要登录才可以下载或查看附件。没有帐号?注册

TOP

将判断改成这种只取数字如果设定时间的时小于10则将"11"改成"空格时间"对比即可
/zhqsystem/zhq 发表于 2015-10-18 00:00



    你的代码。。感觉不如下面这种直观啊。。。

if "%t:~,5%" geq "17:58" if "%t:~,5%" leq "17:59" goto :first11

TOP

回复 10# /zhqsystem/zhq


    多谢。。。为啥其他时间都可以自动关机。。只有17:28到17:29无法关机呢??

TOP

话说 schtasks /create 的 /mo 居然支持 onevent
居然没印象,难道是版本差异?

TOP

返回列表