Search code examples
batch-filedosshutdown

Using user input to customize a .bat shutdown command


Okay. I've figured out a way to turn the shutdown command in a .bat file into an instant messenger, because where I work there are no instant messengers allowed:

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

This works fine, aborting the shutdown command after 5 seconds, but you have to manually edit the computer name and message using a text editor and restart the program in order to send another message. I would like a way to take user input using the SET command that would take the computer name and message as input. I have tried this out, but it didn't work:

    :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

Any ideas?


Solution

  • You need to remove the space between your variable name and the equals sign:

    set /p computer=Enter the computer name:
    

    Otherwise the variable will not be set (it will default to "")