1.

Solve : shutdown issue?

Answer»

I am working on a shut down bat that will shutdown a list of computers remotely. I am having issues getting it to work correctly. I have narrowed the issue down to the shut down command. Any IDEAS on what the cause of the issue might be? It will hit the shutdown command and then loop back to the :SHUT portion of the bat.

Code: [Select]@ECHO OFF
CLS

ECHO THIS WILL SHUTDOWN THE COMPUTERS.....
ECHO.
ECHO.


REM CHECKING TO SEE IF SHUTDOWN LIST EXISTS

IF EXIST "%TEMP%\SMOShutDown.TXT" DEL "%TEMP%\SMOShutDown.TXT"




REM THIS SECTION IS ALL OF THE SYSTEMS THAT WILL BE SCHEDULED TO BE SHUTDOWN

ECHO DOTVCOSMO3>"%TEMP%\SMOShutDown.TXT
ECHO DOTSCOSMO2>>"%TEMP%\SMOShutDown.TXT



REM USE SMOShutDown.TXT IN A FOR LOOP

FOR /f "delims==" %%A IN (C:\DOCUME~1\%USERNAME%\LOCALS~1\Temp\SMOShutDown.TXT) DO SET A=%%A& CALL :SHUT %%A


REM CLEANING UP FILES

IF EXIST "%TEMP%\SMOShutDown.TXT" DEL "%TEMP%\SMOShutDown.TXT"
GOTO EOL


:SHUT
:LOOPSH
SET errorlevel=
ECHO TESTING %A%

REM TEST TO SEE IF SYSTEM IS ACTIVE

ping -n 1 %A% > nul
ECHO %errorlevel%


REM PING ERRORLEVEL OF 0 MEANS SUCCESS
REM PING ERRORLEVEL OF 1 MEANS THE HOST IS NOT FOUND OR TURNED OFF

IF NOT %errorlevel%==0 GOTO OFF


REM PROCEEDING WITH SYSTEM SHUTDOWN
pause
SHUTDOWN -s -f -m \\%A% -t 05 -c "SMO SYSTEM SHUTDOWN DUE TO HEAT"

ping -n 1 -w 25000 1.1.1.1 > nul

GOTO LOOPSH




:OFF

ECHO SYSTEM %A% HAS BEEN SHUTDOWN.....
ping -n 1 -w 500 1.1.1.1 > nul

:EOL

thanks,
WayneThis behavior can occur if the Unlock Computer dialog box appears on the desktop, or if the computer is locked.

http://support.microsoft.com/kb/317371

Quote from: Salmon Trout on July 21, 2009, 01:46:40 PM

This behavior can occur if the Unlock Computer dialog box appears on the desktop, or if the computer is locked.

http://support.microsoft.com/kb/317371



this is not the behavior of the issue I am seeing. If you WISH you can copy and RUN the bat. You just need to change the system names.

when the batch gets to the shutdown command it will loop back to the top of the :SHUT portion and continue to loop. it will not process past the shutdown command. any ideas?If you enable echo, what messages do you see?
it will hit the shutdown command then go back to the :SHUT portion and continue from there. there are no error messages. If I rem out the shutdown command the batch will continue to process correctly. If I copy the command from the batch file and paste it into a cmd window the command will work correctly. That is how I know there is an issue with the batch file and this command.Is the %A% variable being expanded correctly?

what happens if you put echo %errorlevel% straight after the shutdown LINE?
Quote from: Salmon Trout on July 21, 2009, 02:14:11 PM
Is the %A% variable being expanded correctly?


yes it is because I see it when it runs the following line:

Code: [Select]ECHO TESTING %A%

Quote from: Salmon Trout on July 21, 2009, 02:14:11 PM

what happens if you put echo %errorlevel% straight after the shutdown line?


nothing because the lines after the shutdown command do not process.

It is strange because if I enter each command in to a cmd window they work correctly. But, if I run the batch the shutdown command creates a loop.


Discussion

No Comment Found