0

Below is the batch file command I am currently using to shut down remote computers on our LAN.

Here is what it does.

  1. I have specified the remote computers IP address in text file named list.txt
  2. I have added an IP as 0.0.0.0 at the bottom of all the remote computer IPs.
  3. The below batch file will check if the computers are available over LAN.
  4. If the computer is available it will shutdown the remote PC else it will pass on to next IP.
  5. When the batch file reads 0.0.0.0 at last it will self shutdown the master computer.

I cannot run this script for more than 7 remote computers. If I add more than 7 remote PC IP in list.txt the batch file hangs and action does not complete. Please let me know if i made any mistake in the code or How i can fix this issue.

I want to run this batch file for minimum of 12 remote PCs

@echo off
setlocal enableextensions enabledelayedexpansion
for /f %%a in (C:\Users\calcopm\Desktop\list.txt) do (
SET IP =%%a
SET C=0
IF %%a equ 0.0.0.0 (
shutdown /s
) ELSE (
ping -n 1 %%a | find "TTL=" >NUL: && SET C=1
IF !C! equ 1 (
psshutdown \\%%a
) else (
ECHO REMOTE %%a IS NOT REACHABLE
)
)
)
1
  • Your script would work; will it iterate all list.txt lines? (for debugging purposes, try ECHO shutdown /s instead of shutdown /s and ECHO psshutdown \\%%a instead of psshutdown \\%%a)! Are all target IPs running Windows OS?
    – JosefZ
    Jan 21, 2015 at 8:56

1 Answer 1

0

I changed my script as below and converted from BAT to EXE using an application

@echo off
setlocal enableextensions enabledelayedexpansion
for /f %%a in (C:\Users\calcopm\Desktop\list.txt) do (
IF %%a equ 0.0.0.0 (
shutdown /s
) ELSE (
ping -n 1 -w 100
IF errorlevel 1 (
ECHO REMOTE %%a IS NOT REACHABLE
) else (
psshutdown \\%%a
)
)
)

Still I was facing the same problem. As I was running the scripts using exe file(converted using BAT to EXE), I executed using the BAT file it was fine.Then I realised that the BAt to EXE converter had some issues which was affecting the EXE file inturn.

Then I converted BAt to EXE with different application and IT WORKED LIKE A CHARM.

I solved the issue ATLAST!!!!!!!!!!!!! phew!!!!!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .