Batch Network Shutdown

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Phlubs
Posts: 2
Joined: 14 Apr 2011 12:01

Batch Network Shutdown

#1 Post by Phlubs » 14 Apr 2011 12:07

I am attempting to make a batch file that will shut down every computer on my network. I am fairly new to batch in general but I am eager to learn. Here is what I have, apparently it cannot connect to my network itself and ends up only shutting down the computer I am working on. Is it possible, any help? Thanks.

Here is what I have:
@Echo off
cd\
Echo Netshut=Program
REM ****************************
REM * Program Variables *
REM ****************************
set varcomputer=EP-1-1.mysnowleopard.local
goto loop
:EP-1-1.mysnowleopard.local

set varcomputer=EP-1-2.mysnowleopard.local
goto loop
:EP-1-2.mysnowleopard.local

set varcomputer=EP-1-3.mysnowleopard.local
goto loop
:EP-1-3.mysnowleopard.local

set varcomputer=EP-1-4.mysnowleopard.local
goto loop
:EP-1-4.mysnowleopard.local

set varcomputer=EP-1-5.mysnowleopard.local
goto loop
:EP-1-5.mysnowleopard.local

set varcomputer=EP-1-6.mysnowleopard.local
goto loop
:EP-1-6.mysnowleopard.local

set varcomputer=EP-1-7.mysnowleopard.local
goto loop
:EP-1-7.mysnowleopard.local

set varcomputer=EP-1-8.mysnowleopard.local
goto loop
:EP-1-8.mysnowleopard.local

set varcomputer=EP-1-9.mysnowleopard.local
goto loop
:EP-1-9.mysnowleopard.local

set varcomputer=EP-1-10.mysnowleopard.local
goto loop
:EP-1-10.mysnowleopard.local

set varcomputer=EP-1-11.mysnowleopard.local
goto loop
:EP-1-11.mysnowleopard.local

set varcomputer=EP-1-12.mysnowleopard.local
goto loop
:EP-1-12.mysnowleopard.local

set varcomputer=EP-1-13.mysnowleopard.local
goto loop
:EP-1-13.mysnowleopard.local

set varcomputer=EP-1-14.mysnowleopard.local
goto loop
:EP-1-14.mysnowleopard.local

set varcomputer=EP-1-15.mysnowleopard.local
goto loop
:EP-1-15.mysnowleopard.local

set varcomputer=EP-2-1.mysnowleopard.local
goto loop
:EP-2-1.mysnowleopard.local

set varcomputer=EP-2-2.mysnowleopard.local
goto loop
:EP-2-2.mysnowleopard.local

set varcomputer=EP-2-3.mysnowleopard.local
goto loop
:EP-2-3.mysnowleopard.local

set varcomputer=EP-2-5.mysnowleopard.local
goto loop
:EP-2-5.mysnowleopard.local

set varcomputer=EP-2-6.mysnowleopard.local
goto loop
:EP-2-6.mysnowleopard.local

set varcomputer=EP-2-7.mysnowleopard.local
goto loop
:EP-2-7.mysnowleopard.local

set varcomputer=EP-2-8.mysnowleopard.local
goto loop
:EP-2-8.mysnowleopard.local

set varcomputer=EP-2-9.mysnowleopard.local
goto loop
:EP-2-9.mysnowleopard.local

set varcomputer=EP-2-10.mysnowleopard.local
goto loop
:EP-2-10.mysnowleopard.local

set varcomputer=EP-2-11.mysnowleopard.local
goto loop
:EP-2-11.mysnowleopard.local

set varcomputer=EP-2-12.mysnowleopard.local
goto loop
:EP-2-12.mysnowleopard.local

set varcomputer=EP-2-13.mysnowleopard.local
goto loop
:EP-2-13.mysnowleopard.local

set varcomputer=EP-2-14.mysnowleopard.local
goto loop
:EP-2-14.mysnowleopard.local

set varcomputer=EP-2-15.mysnowleopard.local
goto loop
:EP-2-15.mysnowleopard.local

Exit

REM ****************************
REM * Program *
REM ****************************

:loop
echo Shutting down %varcomputer%
shutdown -s -m \\%varcomputer% -t 30 -c "Your computer will now shut down, I am in complete control. Have a nice day, the end is near. "
goto %varcomputer%

Thanks again.

xl1000
Posts: 10
Joined: 01 Feb 2011 06:10

Re: Batch Network Shutdown

#2 Post by xl1000 » 15 Apr 2011 07:28

Check the MS site first, and learn how remote shutdown is being done in a MS environment and what access rights you need.
http://search.microsoft.com/results.aspx?form=MSHOME&mkt=en-us&setlang=en-us&q=remote+shutdown+credentials


But here is another approach for your batch

Code: Select all

@Echo off
cd\
Echo Netshut=Program
REM ****************************
REM * Program Variables *
REM ****************************

call :loop EP-1-1.mysnowleopard.local
call :loop EP-1-2.mysnowleopard.local
call :loop EP-1-3.mysnowleopard.local
call :loop EP-1-4.mysnowleopard.local
call :loop EP-1-5.mysnowleopard.local
call :loop EP-1-6.mysnowleopard.local
call :loop EP-1-7.mysnowleopard.local
call :loop EP-1-8.mysnowleopard.local
call :loop EP-1-9.mysnowleopard.local
call :loop EP-1-10.mysnowleopard.local
call :loop EP-1-11.mysnowleopard.local
call :loop EP-1-12.mysnowleopard.local
call :loop EP-1-13.mysnowleopard.local
call :loop EP-1-14.mysnowleopard.local
call :loop EP-1-15.mysnowleopard.local
call :loop EP-2-1.mysnowleopard.local
call :loop EP-2-2.mysnowleopard.local
call :loop EP-2-3.mysnowleopard.local
call :loop EP-2-5.mysnowleopard.local
call :loop EP-2-6.mysnowleopard.local
call :loop EP-2-7.mysnowleopard.local
call :loop EP-2-8.mysnowleopard.local
call :loop EP-2-9.mysnowleopard.local
call :loop EP-2-10.mysnowleopard.local
call :loop EP-2-11.mysnowleopard.local
call :loop EP-2-12.mysnowleopard.local
call :loop EP-2-13.mysnowleopard.local
call :loop EP-2-14.mysnowleopard.local
call :loop EP-2-15.mysnowleopard.local

goto :eof

REM ****************************
REM * Program *
REM ****************************

:loop
echo Shutting down %1
shutdown -s -m \\%1 -t 30 -c "Your computer will now shut down, I am in complete control. Have a nice day, the end is near. "
goto :eof


aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch Network Shutdown

#3 Post by aGerman » 15 Apr 2011 10:50

Honestly I'm not familiar with remote stuff. If xl1000's script would work for you then a nested loop could make it easier.

Code: Select all

@echo off &setlocal
for /l %%a in (1,1,2) do (
  for /l %%b in (1,1,15) do (
    echo Shutting down EP-%%a-%%b.mysnowleopard.local
    shutdown -s -m \\EP-%%a-%%b.mysnowleopard.local -t 30 -c "Your computer will now shut down."
  )
)


Regards
aGerman

Phlubs
Posts: 2
Joined: 14 Apr 2011 12:01

Re: Batch Network Shutdown

#4 Post by Phlubs » 15 Apr 2011 15:48

Thanks for making that much more compact, simplified the variables a lot.
The main issue I am getting is it claims the path cannot be found when shutting down. I have full access to everything by the way so if needed I can alter anything on my network.
Any ideas? Thanks.

Post Reply