使用用户输入自定义.bat shutdown命令

时间:2012-09-11 22:05:13

标签: batch-file dos shutdown

好。我找到了一种方法将.bat文件中的shutdown命令转换为即时消息,因为在我工作的地方没有允许的即时消息:

    shutdown -s -m \\[computer name] -t 20 -c "[message]"
    PING 127.0.0.1 -n 6
    shutdown -a -m \\[computer name]

这很好用,5秒后中止关机命令,但您必须使用文本编辑器手动编辑计算机名称和消息,然后重新启动程序以发送另一条消息。我想要一种方法来使用SET命令获取用户输入,该命令将计算机名称和消息作为输入。我试过这个,但它不起作用:

    :Jump
    set /P computer ="Enter the computer name: "
    set /P message ="Enter the message: "
    shutdown -s -m %computer% -t 20 -c "%message%"
    PING 127.0.0.1 -n 6
    shutdown -a -m %computer%
    GOTO Jump

有什么想法吗?

1 个答案:

答案 0 :(得分:5)

您需要删除变量名称和等号之间的空格:

set /p computer=Enter the computer name:

否则将不设置变量(默认为“”)

相关问题