Question : Code that restarts all computers in the file. Needs to have a results file

Hi,
Code that restarts all computers in the file. Needs to have a results file

I want a results file on success and failure
And theere are times when i get a message as the user has locked his console so cannot restart.In any case i want a force restart is there anything we can add.

Regards
Sharath
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
:: BATCH SCRIPT START 
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET InputFile=Machines.txt
SET OutputFile=RestartStatus.txt
 
IF NOT EXIST "%InputFile%" ECHO "%InputFile%" file does not exist. &GOTO :EndScript
FOR %%R IN ("%InputFile%") DO IF %%~zR EQU 0 ECHO "%InputFile%" file is empty. &GOTO :EndScript
IF EXIST "%OutputFile%" DEL /F /Q "%OutputFile%"
 
FOR /F %%c IN ('TYPE "%InputFile%"') DO (
        ECHO Processing: %%c
        PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
        IF NOT ERRORLEVEL 1 (
			ECHO Restarting %%c >>"%OutputFile%"
			SHUTDOWN /m \\%%c /r /t 0
        )ELSE (ECHO Unable to connect %%c: system may be offline.))
 
ECHO. &ECHO Script complete. Check "%OutputFile%" file.
:EndScript
ENDLOCAL
EXIT /B 0
:: BATCH SCRIPT END
Open in New Window Select All

Answer : Code that restarts all computers in the file. Needs to have a results file

To force the logoff even if the workstation is locked change line 16 to;
SHUTDOWN /m \\%%c /f /r /t 0

The /f = force logoff
Random Solutions  
 
programming4us programming4us