|
本帖最后由 likeyouli 于 2024-4-12 08:56 编辑
- @echo off
- echo;
- set /p fen=请输入数字多少分钟后睡眠,并按回车:
- echo 请注意,电脑开始倒计时,%fen%分钟后将自动睡眠......
- color 4e
- set /a fen=fen*60
- TIMEOUT /T %fen% /nobreak
- set _Args=%*
- if "%~1" NEQ "" (
- set _Args=%_Args:"=%
- )
- fltmc 1>nul 2>nul || (
- cd /d "%~dp0"
- cmd /u /c echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~dp0"" && ""%~dpnx0"" ""%_Args%""", "", "runas", 1 > "%temp%\GetAdmin.vbs"
- "%temp%\GetAdmin.vbs"
- del /f /q "%temp%\GetAdmin.vbs" 1>nul 2>nul
- exit
- )
- powercfg -h off
- rundll32.exe powrprof.dll,SetSuspendState 0,1,0
- powercfg -h on
- pause>nul
复制代码
下面一种方式,通过计划任务设置,需要提前准备好睡眠bat文件,倒是练习 if 的好方式:- @echo off
- set /p aa=请输入多长分钟以后开始睡眠或休眠(分钟):
- for /f "tokens=1,2 delims=:" %%i in ('time/t') do set shi=%%i&set fen=%%j
- set /a fen=fen+aa
- setlocal enabledelayedexpansion
- set /a shi=100000%shi%%%100000
- echo !shi! 1111111 !fen!
- if !fen! geq 60 (
- set /a fen=fen-60
- if !fen! geq 60 (
- set /a fen=fen-60
- if !fen! geq 60 (
- set /a fen=fen-60
- if !fen! geq 60 (
- set /a fen=fen-60
- if !fen! geq 60 (
- set /a fen=fen-60
- if !fen! geq 60 (
- set /a fen=fen-60
- ) else set /a shi=shi+5&set shijian=!shi!:!fen!
- ) else set /a shi=shi+4&set shijian=!shi!:!fen!
- ) else set /a shi=shi+3&set shijian=!shi!:!fen!
- ) else set /a shi=shi+2&set shijian=!shi!:!fen!
- ) else set /a shi=shi+1&set shijian=!shi!:!fen!
- ) else set shijian=!shi!:!fen!
- set date=%date:~0,10%
- echo !shijian! zongshijian1
- if !fen! leq 9 set fen=0!fen!
- if !shi! geq 24 (
- set /a shi=shi-24&set shi=0!shi!
- set /a ri=!date:~8,2!+1
- set date=!date:~0,4!-!date:~5,2!-!ri!
- )
- if !shi! leq 9 set shi=0!shi!
- set shijian=!shi!:!fen!
- ECHO !DATE!
- SET DATE=!date:~0,4!/!date:~5,2!/!date:~8,2!
- echo !date!
- echo !shijian! zongshijian2
- schtasks /delete /tn "进入睡眠" /f 1>nul 2>nul
- (schtasks /create /tn "进入睡眠" /tr "D:\Personal\Desktop\睡眠或休眠.bat" /sc once /sd "!date!" /st !shijian! /RL HIGHEST)
- endlocal
- echo;
- pause
复制代码
|
评分
-
查看全部评分
|