1.

Solve : shutdown batch script?

Answer»

I am trying to write a batch file that I can use to shutdown/restart computers in my domain REMOTELY. When I type this into the CMD prompt it will work.

Code: [Select]shutdown /s /m \\pcName /t 300 /c "Your message here"


But if I copy that into a batch file so I can use it for different machines as needed it just keeps looping through the first two questions. If I leave echo on I can see where the shutdown command is run, but nothing happens (see bottom of post). Any suggestions?


Code: [Select]@echo off

SET /p _pcName="What computer do you wish to shutdown/restart? "
SET /p _pcAction="Do you want to restart or shutdown the computer? "

if "%_pcAction%" equ "r" goto :pcRestart
if "%_pcAction%" equ "s" goto :pcShutdown

:pcRestart
shutdown /r /m "\\%_pcName% /t 300 /c "5 minutes to AUTOMATIC restart"
goto :confirm


:pcShutdown
shutdown /s /m \\%_pcName% /t 300 /c "5 minutes to automatic shutdown"
goto :confirm

:confirm
set /p _confirm="Shutdown in progress. Would you like to abort? "
if "%_confirm%" equ "y" shutdown /a /m \\%_pcName%
exit

Code: [Select]
C:\Users\[username]\Desktop>SET /p _pcName="What computer do you wish to shutdown
/restart? "
What computer do you wish to shutdown/restart? test_pc

C:\Users\[username]\Desktop>SET /p _pcAction="Do you want to restart or shutdown
the computer? "
Do you want to restart or shutdown the computer? s

C:\Users\[username]\Desktop>if "s" EQU "r" goto :pcRestart

C:\Users\[username]\Desktop>if "s" EQU "s" goto :pcShutdown

C:\Users\[username]\Desktop>shutdown /s /m \\test_pc /t 300 /c "5 minutes to auto
matic shutdown"

C:\Users\[username]\Desktop>SET /p _pcName="What computer do you wish to shutdown
/restart? "
What computer do you wish to shutdown/restart?
have you tried using START in FRONT of each shutdown command?I tried that and it still doesn't work. It opened a new window and started asking the questions again. The original window asked if I wanted to abort the shutdown and then went back to the questions again. The command never actually went through to the remote pc though.



Discussion

No Comment Found