3

I am in the process of creating a batch file that will restart a remote computer then log me back in once the computer has finished restarting. I have everything working except error handling. All I need is to check to see if my shutdown was successful or failed.

Here is the part of my code where I need help:

@echo off
set /p Computer=Restart which computer? 
shutdown -r -m %Computer% -f -t 0

I need to detect if the last line executed successfully or not. Any help is greatly appreciated.

Thanks!

Edit:

Problem solved. Final code below.

@echo off
set DateTime=%Date% %Time%
set Comment=Comment: %DateTime%
set /p Computer=Restart which computer? 
REM Check to see if targeted computer is currently online
ping -n 1 -w 500 %Computer% | find "TTL"
if errorlevel 1 GOTO Error1
cls
shutdown -r -m %Computer% -f -t 0 -c "%DateTime%
REM Checking to make sure shut down was successful
timeout /t 2 /nobreak
wevtutil qe system /q:*[System[EventID=1074]] /c:1 /f:text /rd:true /r:%Computer% | find "%Comment%"
if errorlevel 1 GOTO Error2

Thanks to Kayasax for pointing me to wevtutil.

Thanks to James L. for starting me down the path to adding the date and time in the comment to make sure it was the most recent reboot.

4

1 回答 1

3

您可以尝试查询远程计算机的事件日志并使用 windows7 中的 wevtutil 实用程序检查 eventid 6005 示例

wevtutil qe system /q:*[System[EventID=6005]] /c:1 /f:text /rd:true /r %Computer%
于 2013-06-19T17:26:56.840 回答