Windows 在特定时间关闭计算机。bat

Windows 在特定时间关闭计算机。bat,windows,batch-file,shutdown,Windows,Batch File,Shutdown,我正试图在Windows7上使用BAT文件关闭计算机,我想知道是否有人知道怎么做。这是我到目前为止得到的(它不起作用)。提前谢谢 @echo off :W if %time% == 08:53:00 goto :Y if %time% == 08:54:00 goto :X goto :W :Y taskkill /f /IM "iexplore.exe" :X shutdown.exe /s /f /t 60 /c " Sleeeeeeeep " 你为什么想要一个.bat文件?您可

我正试图在Windows7上使用BAT文件关闭计算机,我想知道是否有人知道怎么做。这是我到目前为止得到的(它不起作用)。提前谢谢

@echo off
 :W
if %time% == 08:53:00 goto :Y
if %time% == 08:54:00 goto :X
goto :W

 :Y
taskkill /f /IM "iexplore.exe"
 :X
shutdown.exe /s /f /t 60 /c " Sleeeeeeeep " 

你为什么想要一个.bat文件?您可以在Windows 7上使用powershell。在命令提示符下运行此命令,无需担心脚本文件,只需执行@Andrew提到的计划任务:

schtasks /create /tn "shutdown" /sc daily /st 08:53 /tr "powerShell -command { taskkill /f /IM iexplore.exe; Start-Sleep -Seconds 3600; Stop-Computer -Force }"

它也很有效。你只要把它放在正确的时间格式。它可以正常运行所有其他windows版本

例如:

%时间%==00:00:0.00

我只是修改了你的时间格式,在我的电脑上运行,它运行得非常好

只有你把它的24小时时间格式


做这样的循环对我来说不是个好主意。为什么不是执行批处理文件的计划任务??执行关闭文件应该足够了,这也会杀死IE。顺便说一句,如果你在控制台中运行
echo%time%
,你会得到确切的格式吗?注意前导空格和秒小数。从goto语句中删除冒号:。关机后不需要.exe。否则,语法看起来不错。在开始之前暂停一下,否则你将在这个循环中度过你生命中除了2分钟以外的所有时间。第一:不要在没有空闲时间的情况下构建一个循环,以避免最大的CPU负载。秒:
%time%
将时间缩短到厘米秒(
10:23:46,72
),它永远不会精确匹配精度为秒的时间字符串(
10:23:46
)。第三:是的,计划好的任务是一种更好的方式。
@echo off
:W
if %time% == 20:53:0.00 goto :Y
if %time% == 20:54:0.00 goto :X
goto :W

:Y
taskkill /f /IM "iexplore.exe"
:X
shutdown.exe /s /f /t 60 /c " Sleep... "