/build/static/layout/Breadcrumb_cap_w.png

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?

0 Comments   [ + ] Show comments

Answers (6)

Posted by: GillySpy 13 years ago
7th Degree Black Belt
0
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:
@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.
Posted by: RichB 13 years ago
Second Degree Brown Belt
0
We use Online shutdown scripts instead of Offline, just for this reason.
Posted by: GillySpy 13 years ago
7th Degree Black Belt
0
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
Posted by: ronco 13 years ago
Third Degree Brown Belt
0
Why not script the building of a Schedule Task (for Windows machines)? There's no ambiguity about when that would run. r2
Posted by: RichB 13 years ago
Second Degree Brown Belt
0
Then the user would not be able to stop the shutdown and we have allowed them to cancel our shutdown scripts.
Posted by: GillySpy 13 years ago
7th Degree Black Belt
0
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)
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ