admin管理员组文章数量:1581982
bat实现自动关机命令
实现只支持整数数字输入,以及0001此类参数还原
@echo off &setlocal enabledelayedexpansion
color a
title 系统定时注销
ECHO. 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
ECHO. ■ 定时关机命令 ■
ECHO. 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
echo.
echo. 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
echo. ■ 桔子 - 2024-1-9 ■
echo. 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
:start_text
echo.
echo.
set /p str=■ 请输入设定关机的时间 (单位秒) 并按下回车键开始计时:
call :stringlenth %str% num
::echo 字符串长度为:%num%
if "%num%"=="" goto error
set /a stat=num-1
set key=false
set /a KeyNumber=0
for /l %%i in (0,1,%stat%) do (
set res=!str:~%%i,1!
set flag=false
echo !res! |findstr [0-9] >nul && set flag=true
if not !flag!==true goto error
if !res!==0 (
if %%i==0 (
set key=true
set /a KeyNumber+=1
) else if !key!==true (
set /a KeyNumber+=1
)
) else (
set key=false
)
if !key!==false (
set keyString=!keyString!!res!
)
if %%i==%stat% (
set key=false
set /a str1=!keyString!+1
title 系统将在 !keyString! 秒后注销关机
echo.
echo.
echo. 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
echo. ■ !keyString! 秒后注销关机设置已完成 ■
echo. 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
echo.
echo.
shutdown -s -t !str1!
set str2=""
set/p str2=■ 按【 Y 】键取消计划任务,或按任意键退出脚本...
if /i "!str2!"=="y" (
title 系统计划关机已取消.
echo ■ 系统计划关机已取消.
shutdown -a
pause >nul && exit /b
) else (
exit /b
)
)
)
endlocal
:error
echo ■ 输入的 %str% 格式错误!可能包含空格 参数需要为整数数字...
goto :start_text
cls
:StringLenth
set theString=%~1
if not defined theString goto :eof
set Return=0
:StringLenth_continues
set /a Return+=1
set thestring=%thestring:~0,-1%
if defined thestring goto StringLenth_continues
if not \"%2\"==\"\" set %2=%Return%
goto :eof
版权声明:本文标题:bat实现自动关机命令 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727887079a1136049.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论