Restarting a server at a certain time from accross the LAN.
Just a quick entry as i got an email requesting this today, “How can i schedule a restart on a remote server to run out of hours?”
This script uses at.exe which is soon replaced by schtasks.exe. This can only be run by an administrator of the server you wish to restart, obviously.
Rem setting vars:
set server=servertorestart
set time=05:00
REM performing check for previous file and deleting it:
if exist \\%server%\c$\rebootme.bat del \\%server%\c$\rebootme.bat
Rem Creating reboot batch file:
echo shutdown -r -t 03 >> \\%server%\c$\rebootme.bat
Rem Schedueling the job:
at \\%server% %time% c:\rebootme.bat
To Create a reuseable, error checking script with idiot proof options! save the following as a .bat file:
@echo off
cls
Rem setting vars:
set /p server=[Please enter the name of the server you wish to restart:]
cls
echo Selected server = %server%
set /p time=[Please enter the time in HH:MM format at which you wish to restart the server: e.g. 05:00]
cls
REM performing final idiot check
echo Are you absolutely sure you wish to restart %server% at %time%?
Pause
REM performing check for previous file and deleting it:
if exist \\%server%\c$\rebootme.bat del \\%server%\c$\rebootme.bat & echo deleted previous file
Rem Creating reboot batch file:
echo shutdown -r -t 03 >> \\%server%\c$\rebootme.bat
Rem Ensuring reboot file exists:
if exist \\%server%\c$\rebootme.bat echo reboot script created successfully.
if not exist \\%server%\c$\rebootme.bat goto Failed
Rem Schedueling the job:
at \\%server% %time% c:\rebootme.bat
Echo Job schedueled, Script complete.
pause
:failed
echo something failed, I’d look into that if i were you.
pause
exit
We had a problem recently with the adobe professional suite installing a local printer on the XenApp server, this was great for users licensed to use Adobe Professional, but for users that weren’t it gave them a possibility to infringe the licensing simply by printing to this printer.
Recent Comments