Alerts are pretty clunky to use for reboots. Anyone have a better method, aside from a scheduled task?
I have a separate inventory application that runs. PDQ Inventory and Deploy.
If it detects a server or workstation that needs a reboot for some reason, it schedules a reboot when users are not there. I have had the windows update and task scheduler fail too many times in the past to trust them
I also have the inventory application check for how long they have been on. If laptops are left at work and have been on for over a week, I restart them.
Desktops I scan and force shutdown every night after any updates/patches apply.
You should be able to do the same thing with SimpleHelp and a couple of powershell scripts, or WMI scripts.
Toolbox that prompts for date and time and schedules a reboot using task scheduler and shutdown -r
::::::::::::::::::::::::::::::::::::::::::::
:: Elevate.cmd - Version 4
:: Automatically check & get admin rights
:: see “https://stackoverflow.com/a/12264592/1016343” for description
::::::::::::::::::::::::::::::::::::::::::::
@echo off
CLS
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================
: Prompt technician for date and time?
ServerUtilsAskTech(Schedule a reboot, title)
ServerUtilsAskTech(Accept,submit)
set mydate=“ServerUtilsAskTech(Date (mm/dd/yy),text)”
set mytime=“ServerUtilsAskTech(Time (24-hour clock hh:mm),text)”
:init
setlocal DisableDelayedExpansion
set cmdInvoke=1
set winSysFolder=System32
set “batchPath=%~0”
for %%k in (%0) do set batchName=%%~nk
set “vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs”
setlocal EnableDelayedExpansion
:checkPrivileges
NET FILE 1>NUL 2>NUL
if ‘%errorlevel%’ == ‘0’ ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if ‘%1’==‘ELEV’ (echo ELEV & shift /1 & goto gotPrivileges)
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************
ECHO Set UAC = CreateObject^(“Shell.Application”^) > “%vbsGetPrivileges%”
ECHO args = "ELEV " >> “%vbsGetPrivileges%”
ECHO For Each strArg in WScript.Arguments >> “%vbsGetPrivileges%”
ECHO args = args ^& strArg ^& " " >> “%vbsGetPrivileges%”
ECHO Next >> “%vbsGetPrivileges%”
if ‘%cmdInvoke%’==‘1’ goto InvokeCmd
ECHO UAC.ShellExecute “!batchPath!”, args, “”, “runas”, 1 >> “%vbsGetPrivileges%”
goto ExecElevation
:InvokeCmd
ECHO args = “/c “”” + “!batchPath!” + “”" " + args >> “%vbsGetPrivileges%”
ECHO UAC.ShellExecute “%SystemRoot%%winSysFolder%\cmd.exe”, args, “”, “runas”, 1 >> “%vbsGetPrivileges%”
:ExecElevation
“%SystemRoot%%winSysFolder%\WScript.exe” “%vbsGetPrivileges%” %*
exit /B
:gotPrivileges
setlocal & cd /d %~dp0
if ‘%1’==‘ELEV’ (del “%vbsGetPrivileges%” 1>nul 2>nul & shift /1)
::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
SCHTASKS /CREATE /SC ONCE /TN “Reboot” /TR “C:\Windows\System32\shutdown.exe -r” /RU system /V1 /Z /ST %myTime% /SD %myDate%
I can’t seem to get this working. Getting error “The system cannot find the batch label specified - gotPrivileges”
It’s probably the way quotes are handled. Here’s a toolbox you can download and use.
https://drive.google.com/file/d/1Z64mqoPxh9BrFED7mh5fjPRT2A7xFXyH/view?usp=sharing