.bat file does not execute

1

I have a file with the following command to turn off some machines on the network.

FOR /F %i IN (C:\estacoes.txt) DO SHUTDOWN /s /t 01 /m %i

Where stations.txt is a file with the names of machines to be turned off.

When I open cmd and run this command in hand it works correctly. But when I save in a .bat file and try to run it does not execute.

I tried to run as administrator and it also did not work.

    
asked by anonymous 18.01.2018 / 19:31

2 answers

1

I did it this way and it worked

echo off
cls
for /F %%i in (%homedrive%\estacoes.txt) do (
SHUTDOWN /s /t 01 /m %%i
)

Example list I've done:

windowsxp
portaria
novowindows

I tested on a Windows x64 (Windows 8.1) to shut down other machines and then directly and at the end itself, then tested on an x32 machine (Windows XP SP2), was also correctly.

I just could not turn off the machine with Windows 8.1 because it needs to authenticate for a user of it.

If you use ping you can check if the machine is plugged in or connected to the network before attempting to shut down, this prevents long and unnecessary wait for FOR .

    
03.03.2018 / 19:29
0

The syntax of FOR for a single-line command is directed only to when it will use the Console directly, for a BATCH file the /F directive is not required.

@echo off
FOR %%i IN (C:\estacoes.txt) DO SHUTDOWN /s /t 01 /m %%i
pause

In addition, you will have to use %%i instead of %i .

  

Note: Remove pause at the end of the line if you are not debugging this code.

    
18.01.2018 / 19:42