windows 批处理文件 - X 分钟后关闭计算机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6439955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Batch File - Shutdown Computer after X Minutes
提问by Owen
I want to make a batch file that takes a user input in minutes, and will shutdown the computer after the time is up.
我想制作一个批处理文件,在几分钟内接受用户输入,并在时间到后关闭计算机。
I know how to shutdown the computer after a set amount of time is up, I've just been having trouble setting that time to the user input.
我知道如何在设定的时间结束后关闭计算机,我只是在为用户输入设置该时间时遇到问题。
回答by Maynza
I think this will do what you want.
我认为这会做你想做的。
@echo off
set /p mins=Enter number of minutes to wait until shutdown:
set /a mins=%mins%*60
shutdown /s /t:%mins%
According to http://ss64.com/nt/shutdown.htmlthe most you can wait is 10 minutes, so if you need to wait longer you would need to add some sort of artificial timer, most likely using something like TIMEOUT if your system supports it (mine doesn't) or ping.
根据http://ss64.com/nt/shutdown.html,您最多可以等待 10 分钟,因此,如果您需要等待更长时间,则需要添加某种人工计时器,如果您的系统支持它(我的不支持)或 ping。
@echo off
set /p mins=Enter number of minutes to wait until shutdown:
for /L %%a in (0,1,%mins%) do (
PING -n 60 127.0.0.1>nul
)
shutdown /s
回答by Trevor
Check out this thread.
看看这个线程。
https://superuser.com/questions/215531/windows-7-shut-down-pc-after-specified-amount-of-time
https://superuser.com/questions/215531/windows-7-shut-down-pc-after-specified-amount-of-time
Put this code in it after the @echo off line:
将此代码放在@echo 离线之后:
shutdown -s -t 1800
关机 -s -t 1800
回答by user2103527
@echo off
title Shutdown Input
set /p mins=Enter number of minutes to wait until shutdown:
set /a mins=%mins%*60
shutdown.exe -s -t %mins%
回答by Tobi G.
- Create a file with bat as extension (such as delayed.bat).
You can use the Editor under Accesstheitroades for that. - Write the following lines into the file and save it (The file has to end with
.bat
) :
- 创建一个以bat为扩展名的文件(如delayed.bat)。
为此,您可以使用 Accesstheitroades 下的编辑器。 - 将以下行写入文件并保存(文件必须以 结尾
.bat
):
@echo off set /p time=minutes: set /a time=%time%*60 shutdown /a shutdown /s /f /t %time%
@echo off set /p time=minutes: set /a time=%time%*60 shutdown /a shutdown /s /f /t %time%
- set /p lets the user input something
- set /a interprets expressions (calculations)
- /a abortsearlier shutdown (counter)
- /s stands for shutdown
- /f stands for forceprograms to close(optional).
- /t stands for the time in seconds. (for example: 60s * 10 = 10 min)
- Doubleclick the file and enter after how many minutes you computer shuts down.
- To abort shutdown: enter a big number (such as 10000000).
- Doubleclick the file and enter after how many minutes you computer shuts down.
- set /p 让用户输入一些东西
- set /a 解释表达式(计算)
- /a中止较早的关闭(计数器)
- /s 代表关机
- /f 代表强制关闭程序(可选)。
- /t 代表以秒为单位的时间。(例如:60s * 10 = 10 分钟)
- 双击该文件并在您的计算机关闭几分钟后输入。
- 中止关机:输入一个大数字(例如 10000000)。
- 双击该文件并在您的计算机关闭几分钟后输入。
回答by Tobi G.
Create a batch file, and put this code in it after the @echo off line:
创建一个批处理文件,并把这段代码放在@echo 离线之后:
shutdown -s -t 1800
The computer will shutdown 30 minutes (1800 seconds) after running the batch file.
运行批处理文件后,计算机将关闭 30 分钟(1800 秒)。
To cancel a shutdown initiated by that batch file, you can go to Start → Run and type:
要取消由该批处理文件启动的关机,您可以转到“开始”→“运行”并键入:
shutdown -a
Or put that in its own separate batch file, then run it to cancel a shutdown.
或者把它放在它自己单独的批处理文件中,然后运行它来取消关机。
回答by Nuclear Donut
Put this in a batch file and run.
把它放在一个批处理文件中并运行。
@echo off
@setlocal
color 1E
echo üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü
echo Y ú????T
echo Y SHUTDOWN COMPUTER WITH TIMER 3 ? 3T
echo Y à???ùT
echo. ?????????????????????????????????????????????????
echo.
echo.
echo ----------------------------------------
Set /P _abort=abort shutdown? (y, *):
echo ----------------------------------------
If /i "%_abort%"=="y" shutdown /a
If /i "%_abort%"=="y" goto step1
Set /P _timer=shutdown computer after minutes:
echo ------------------------
set /a _result= _timer * 60
shutdown /s /t %_result%
:step1
echo Job Done!
pause