Jump to content

Shutdown last running pc on the LAN with server


Recommended Posts

I have a LAN with 4 PCs and one Synology server. I wish that every time a computer is turned off, it runs a batch (from windows pc) and see if other PCs are on, - if any is on do nothing, - otherwise runs a command that shuts down the server.


Here is what I have at the moment:



@echo off
PING 192.168.1.10
IF %ERRORLEVEL% EQU 1 plink root@192.168.1.10 -pw MYPASSWORD shutdown -s -t 00

But I would like to do something like: 


http://i.imgur.com/BLAVCBt.png


BLAVCBt.png


THANK YOU!!


Edited by ruelle
Link to comment
Share on other sites


Something like:

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS

SET /A Points=0

FOR /L %%A IN (10,1,14) DO CALL :DoPing 192.168.1.%%A

IF %Points% GTR 0 plink root@192.168.1.10 -pw MYPASSWORD shutdown -s -t 00

 

GOTO :EOF

 

:DoPing

FOR /F %%B IN ('PING -n 1 %1 ^|FIND "TTL") DO SET /A Points+=1

 

http://ss64.com/nt/ping.html

 

A successful PING does NOT always return an %errorlevel% of 0
Therefore to reliably detect a successful ping - pipe the output into FIND and look for the text "TTL"

 

 

jaclaz

Link to comment
Share on other sites

http://ss64.org/viewtopic.php?pid=8188

 

http://stackoverflow.com/questions/28304099/batch-script-to-ping-other-pc-in-my-lan-and-shutdown-together-last-online-pc

 

http://www.msfn.org/board/topic/173438-shutdown-last-running-pc-on-the-lan-with-server/

 

http://forum.synology.com/enu/viewtopic.php?f=145&t=96609&p=364122#p364122

 

http://www.dostips.com/forum/viewtopic.php?f=3&t=6245

 

I think last one will be more easy to use thank you for the answer!

 

@echo off
set "flag="
ping 192.168.1.1 -n 2  |find /i "TTL=" >nul && set flag=1
ping 192.168.1.2 -n 2  |find /i "TTL=" >nul && set flag=1
ping 192.168.1.3 -n 2  |find /i "TTL=" >nul && set flag=1
ping 192.168.1.4 -n 2  |find /i "TTL=" >nul && set flag=1
if not defined flag echo shutdown server

Edited by ruelle
Link to comment
Share on other sites

Sure, as the guy that provided it commented, for four PC's that is fine. :thumbup

The FOR /L loop utility becomes evident when you have the whole range 1÷255 to scan or more...

... and the "points adding system" may come of use when (if) you need to add some other condition (like -say - a Ping result that is good but that has a too high TTL or response time) ...

 

 

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Here is a way of doing what you want, only using a VBS script

'-> Wmi ObjectDim Wmi :Set Wmi = GetObject("winmgmts:\\.\root\cimv2")'-> Varibles For RuntimeDim Col, i, Ip, Obj'-> Array To Hold All The IP AddressesIp = Array("127.0.0.1","192,123,55,1","127.0.0.24","123.55.72.123")'-> Start First Loop Threw IP For Each i In Ip '-> Passing i As Ip Address To Be Ping  Set Col = Wmi.ExecQuery("Select * From Win32_PingStatus where Address = '"&i&"'")'-> Second Loop To Ping Ip Address  For Each Obj in Col   If IsNull(Obj.StatusCode) Or Obj.StatusCode<>0 Then'-> Code Here For Computer That Does Not Respond      Wscript.Echo "Computer Ping Missing : " & i   Else'-> Code Here When The Computer Does Respond    WScript.Echo "Computer Ping Confirm : " & i   End If  Next Next 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...