- for /f %%i in (computername.txt) do (shutdown -m %%i -s -f -t 5)
这个语句是个批处理命令的语句,可以通过在文本文件中编写,然后将后缀名改为bat来运行。 还需要建立一个文本文件computername.txt来提供需要关闭的计算机名。
这个语句中主要包含两个命令:
1.shutdown命令
C:\>shutdown
Usage: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "c
omment"] [-d up:xx:yy]
No args Display this message (same as -?)
-i Display GUI interface, must be the first option
-l Log off (cannot be used with -m option)
-s Shutdown the computer
-r Shutdown and restart the computer
-a Abort a system shutdown
-m \\computername Remote computer to shutdown/restart/abort
-t xx Set timeout for shutdown to xx seconds
-c "comment" Shutdown comment (maximum of 127 characters)
-f Forces running applications to close without warning
-d [u][p]:xx:yy The reason code for the shutdown
u is the user code
p is a planned shutdown code
xx is the major reason code (positive integer less than 256)
yy is the minor reason code (positive integer less than 65536)
以上是shutdown的详细使用方法。
2.for 语句
详解见http://mintank.blog.51cto.com/blog/2544524/939437
注意:我最近在使用这个批处理的时候做了一些修改然后去运行,居然不能成功执行,以为是代码哪里错了,仔细检查n遍,简直精确到每个字节(不带回车符是60byte)最后无奈的失败了,后来突发奇想,改了批处理的文件名,居然又可以了(英文名,只要是字母型的就不行,中文名才可以)。我很郁闷,求大神解释原因啊!!!
转载于:https://blog.51cto.com/mintank/939418