Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 800
Connoronnor Avatar asked Apr 18 '26 10:04

Connoronnor


1 Answers

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 "")

like image 136
Will Richardson Avatar answered Apr 20 '26 11:04

Will Richardson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!