Batch Files

I’m tinkering with batch files at work. I got a couple working (like starting a service that otherwise won’t start in safe mode, etc.) but I’d like to get this one working and am not having any luck.

I want to be able to run this and be prompted for the computer name, countdown, and comment to provide while shutting down a computer remotely. I do this when I have a machine doing something overnight and I don’t want it running till the morning. I shut it down at 2am for example.

Here is what I have.


:: Remote Shutdown
:: Shut down a computer remotely
::
@ECHO OFF

echo Enter Computer Name:
set /p computer=

echo Enter Time Countdown:
set /p t=

echo Enter Comment:
set /p comment=

echo shutdown -m \%computer% -s -t %t% -c “%comment%”


When I run the above batch file, I get the prompts but at the end nothing happens. If I remove the last echo, it just loops. Ending at the -s and deleting everything else does nothing either. If I “echo %computer% %t% %comment%” it shows what I typed in when prompted…so the variables are holding the correct data. It’s the line with the actual command that doesn’t work. If I type the command itself into a command line, it’ll shut down the PC in question.

Can someone help me please? I’d appreciate it. I wasn’t able to find what I was looking for online (been googling last hour or so).

Rep points will be given :).

I got this all worked out.

I had the batch file named shutdown.bat. I guess you can’t name it the same as the command. Also, I had to remove the last echo (before the command).