Shut down script (eventually) running on PCs that are turned off
I'm trying to use the built in Offline KScript to shut down a Windows PC for the following:
* Runs every night at 10pm to shut down any PCs that people are leaving on.
* Run manually to shut down PCs I woke up (using WOL) to work on in the evening.
I assumed that this script would only run on the PCs that are turned on, but it seems to run on the machines that are off the next time they are turned on. So people are booting up and their PC wants to immediately shut down. Does this make sense? Should I change this to a different kind of script? Is there a way that I can build a smart label for PCs that are turned on?
* Runs every night at 10pm to shut down any PCs that people are leaving on.
* Run manually to shut down PCs I woke up (using WOL) to work on in the evening.
I assumed that this script would only run on the PCs that are turned on, but it seems to run on the machines that are off the next time they are turned on. So people are booting up and their PC wants to immediately shut down. Does this make sense? Should I change this to a different kind of script? Is there a way that I can build a smart label for PCs that are turned on?
0 Comments
[ - ] Hide Comments

so that the conversation will remain readable.
Answer this question
or Comment on this question for clarity
Answers
An offline script will run at the next available time so you should have some checking in your script for the local time. Like this if you were doing a batch:
This way the script may run at 9am but do nothing.
@echo off
REM this will only shutdown the machine if the time is from 6pm to 7:59am
REM echo %time%
FOR /F "delims=:" %%j in ('echo %time%') do set i=%%j
goto checkhour
:checkhour
echo %i%
if "%i%"=="18" goto runshutdown
if "%i%"=="19" goto runshutdown
if "%i%"=="20" goto runshutdown
if "%i%"=="21" goto runshutdown
if "%i%"=="22" goto runshutdown
if "%i%"=="23" goto runshutdown
if "%i%"=="0" goto runshutdown
if "%i%"=="1" goto runshutdown
if "%i%"=="2" goto runshutdown
if "%i%"=="3" goto runshutdown
if "%i%"=="4" goto runshutdown
if "%i%"=="5" goto runshutdown
if "%i%"=="6" goto runshutdown
if "%i%"=="7" goto runshutdown
goto end
:runshutdown
echo %time%
REM "%windir%\system32\shutdown.exe" -s -f -c "" -t 180
:end
This way the script may run at 9am but do nothing.
Please log in to comment
An online script can be good but it takes resources away from the server. If it were my kbox I would be doing this type of task offline because of it's potential to go to many clients and for the agent to be offline, but there's definitely more than one way to skin a kat
Please log in to comment
you can build a scheduled task. my goal is that I simply want to take an existing script and "transform" it by checking the time first. The other tasks in the script could be complex. I do not want to have to rewrite it as a scheduled task (e.g. as one batch file)
Please log in to comment
Comments