network remote shutdown batch files

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
mike pittenger
Posts: 1
Joined: Mon Jan 21, 2008 12:39 am

network remote shutdown batch files

Post by mike pittenger » Mon Jan 21, 2008 12:43 am

I am new to scripting and batch files in general. My goal is to shutdown a network of 2000 or so computers. I want to ping before shutting down to avoid a delay.

The first batch file (shutdown_list)will have the names of the computers and run the second batch file (shutdown_single)with the ping and shutdown.exe.

The problem I am having is the second batch file will not pick up the computer names from the first.

Any help will be appreciated.

shutdown_list.bat:

shutdown_single ad-dao-bm-03.casd
shutdown_single ad-dao-bm-04.casd
shutdown_single ad-dao-bm-05.casd

shutdown_single.bat:

@echo off
MachineName=%1
ping -n 1 -w 800 %MachineName%if not errorlevel 1 goto MachineOKecho Cannot ping machine %MachineName%. Aborting.goto Fini:MachineOK
shutdown.exe -s -f -m %MachineName% -t 60 -c "Daily shutdown, please save any work and shut down again if restarted."
:Fini

User avatar
jhicks
Posts: 1789
Joined: Sun Jan 21, 2007 11:31 pm

network remote shutdown batch files

Post by jhicks » Tue Jan 22, 2008 2:30 am

Change MachineName=%1toset MachineName=%1Or forgo adding another variable and simply use %1 instead of %machinename%

User avatar
imperialxt
Posts: 3
Joined: Wed Apr 16, 2008 6:43 pm

network remote shutdown batch files

Post by imperialxt » Wed Apr 16, 2008 6:46 pm

hey i'm rather new to this stuff i'm still a studentbut i'm curious if there is a way that i can get my shutdown bat file to prompt for which computer on the network i want to shutdown so it would like pop up and say insert name of computer and i would type "Computer1"any suggestions?

User avatar
imperialxt
Posts: 3
Joined: Wed Apr 16, 2008 6:43 pm

network remote shutdown batch files

Post by imperialxt » Wed Apr 16, 2008 11:34 pm

thanks that will come in handy i'm sure. I'm very interested in this type of scripting aka vbs any suggestions as to where a good place to learn it might be ?.

User avatar
imperialxt
Posts: 3
Joined: Wed Apr 16, 2008 6:43 pm

network remote shutdown batch files

Post by imperialxt » Thu Apr 17, 2008 3:17 am

thanks that looks like it will be very good :Palso is there a slight addition i can make to the script that will make it shutdown all computers ? or do i need to list all the computers as above ?

User avatar
felimclarke
Posts: 1
Joined: Wed May 26, 2010 11:34 pm

network remote shutdown batch files

Post by felimclarke » Wed May 26, 2010 11:49 pm

Hey,

Sorry to bother you but I am having a few problems with the script/batch file listed above if you could maybe point me in the right direction to getting to working please. I can get it working in on the 1st computer in the list but then it finishes running it doesn't move on to the next PC in the list.

As with mike

User avatar
jvierra
Posts: 13615
Joined: Tue May 22, 2007 9:57 am
Contact:

network remote shutdown batch files

Post by jvierra » Thu May 27, 2010 12:34 am

Try this:



for /F %i in (servers.txt) do
shutdown.exe -s -f -m %i -t 60 -c "Daily shutdown, please save any work and shut down again if restarted."



All on one line.

If in a batch file use double % signs.


Locked