Home:ALL Converter>Windows Scheduled Restart Script issues

Windows Scheduled Restart Script issues

Ask Time:2015-12-07T05:46:34         Author:Leptonator

Json Formatter

Setting the Scheduled task, we use:

REM SET THE DATE WE WANT THE TASK TO RUN
SET STARTDATE=12/06/2015

SCHTASKS /S SERVER /CHANGE /TN "SERVICE_RESTART" /RU "" /DISABLE
SCHTASKS /S SERVER /F /CREATE /TN "SERVER_RESTART" /RU "" /RP "" /SC ONCE  /ST:02:11 /SD %STARTDATE% /TR "D:\WORK\scripts\Server_Reboot.bat 1"

Have coded the following windows batch script and has have some issue when running last night..

@echo off
SET /A ARGS_COUNT=0

FOR %%A in (%*) DO SET /A ARGS_COUNT+=1

rem ECHO %ARGS_COUNT%

If %ARGS_COUNT% == 0 goto leave
If %ARGS_COUNT% == 1 goto continue

:continue
echo we would restart here
SCHTASKS /CHANGE /TN "SERVICE_TCRESTART" /ENABLE /RU ""
SCHTASKS /CHANGE /TN "SERVER_RESTART" /DISABLE /RU ""
shutdown /r /t 0 /c "scheduled reboot" /f /d P:0:0
goto end

:leave
echo we are done
goto end

:end
echo bye

NOTE: The script has to run with: "Server_Reboot.bat 1" - I am not sure if I have to schedule the server restart with Windows 2003 with quotes or not? Windows 2008 systems seem OK/

Did find an alternative to the Windows Shutdown and I am wondering if I need to use it instead of shutdown.exe:

WMIC OS Where Primary=TRUE Call Reboot

Thanks!

Author:Leptonator,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34123189/windows-scheduled-restart-script-issues
yy