Discussion Locked

Remote Shutdown batch file

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi, I'm have a problem executing a shutdown batch file using the Task scheduler W2K3.

I created a batch file (Shutdown.bat) on the W2K server that has a single command:

shutdown -s -m \\Computername

If I run the command from the command prompt using the actual name of the client PC it works....the client shuts down...OK!
However, if I set the .bat to run as a task the command prompt pops up and I see the command executing over and over and over.
Its like it goes into a loop then I have to press Ctrl -C to terminate the batch file...the client PC does not shut down either.

Whats the problem here...any help greatly apprciated.

Jason.

8 replies

by mlacombe

Are you scheduling the task to run as a user that has admin rights on the PC? Make sure your username and password are set correctly. Have you also tried by IP to see if that made any difference?

by shaun.clarke

I know this is an old thread, but if anyone else is still interested, there is a logical explanation for this infinite loop behaviour.

Assuming you were in a command prompt and were in the folder where shutdown.bat resides, when the batch files calls your shutdown command, it will run the 'shutdown' batch file from the current folder instead of %windir%\system32 as files in the current folder have a higher priority than those in the %path% environment variable.

I've run into this before. Strange behaviour, but it does make sense if you think about it.

by dymax

Hi, I am also looking for the batch file to shutdown the PCs in the lab. i tried the follwing command
shutdown ?i \\computername -s. When a save it as a bacth file it does not work. Can someone help me.

Thanks

by kevin

I have tested this batch file created from multiple sources on 24 computers with sucess, just create a txt file called computers.txt and enter ip address or computer names that you wish to shut down, 1 per line. Copy bat file and txt file to root of server and run bat file, create a scheduled task to run bat file at whatever time you want to shutdown the computers

@echo OFF
@setlocal
(set command=type C:\COMPUTERS.txt)
for /f "usebackq tokens=*" %%i in (`%command%`) do call :process_line %%i
echo next to last line: %old_line%
goto :eof
:process_line
(set old_line=%new_line%)
(set new_line=%*)
@START shutdown -s /f /t 20 /c "Switching Off System" -m \\%new_line%
goto :eof

This discussion is closed to new replies.