There are many ways to shut down a computer, and many ways to automate those shutdowns to happen at a specific time of day. Most solutions do a form of brute force shutdown whereby they just turn off with no options for the user to cancel. Some are also tricky to implement or to customise the times of the shutdowns.
This is my implementation of a shutdown process for a local charity.
The application is designed to maintain a list of ti mes when the computer will attempt to shut down. The users of the computer will be notified of the configured shutdown times, and be able to cancel them if they are still working on the machine. This allows you the benefit of setting multiple shut down attempts that users can override.
Additional shutdown times can also be added by the user if required and through the configuration tool the administrators can choose to lock out the functionality to add/remove the configured shutdowns.
The tool is split into two parts. Firstly there is the system service. This component manages all of the shutdowns on the machine and performs the actual shutdowns. It can read the XML configuration file which can be deployed using a GPO, and co-ordinates the shutdowns between all of the users on the computer. It also manages the system wake timers to bring the computer out of sleep in sufficient time for a shutdown to be executed.
There is also a user interface which is launched whenever a user logs on. Typically this hides itself away in the system tray. The interface provides notifications to users about shutdowns which are configured and allows them to create a new scheduled shutdown and cancel an existing scheduled shutdown.
The target computer must be running Windows Vista or newer, 32 or 64 bit. The .Net Framework 3.5 is also required to run this service, however you will be prompted to install this if it is not available on your computer.
Installation and Configuration
The whole package has been designed so that it can be deployed and configured through a GPO. It can also be installed manually by simply running the setup.exe in the downloaded file or you can script the installation using a configuration management platform. There are no configuration options in the installation.
The configuration of the shutdowns is controlled through an XML file. This file sits in the installation directory. The default installation directory is “C:\Program Files (x86)\Craig Tolley\Desktop Shutdown Service”. The XML configuration file is called ‘shutdowns.xml’.
The structure of the XML file and the default contents of the file are shown below:
<?xml version="1.0" encoding="utf-8" ?> <shutdown-configuration> <!-- Define all of your shutdowns here. Entries should be in the format <shutdown>18:00</shutdown> --> <shutdowns> <shutdown>18:00</shutdown> <shutdown>23:00</shutdown> </shutdowns> <!-- Define the settings for the application. --> <settings> <setting name="AllowCancelShutdown">true</setting><!-- Default: true--> <setting name="AllowAddCustomShutdown">true</setting><!-- Default: true--> <setting name="WakeComputerFromSleep">true</setting><!-- Default: true--> <setting name="NotifyOnAppStart">true</setting><!-- Default: true--> </settings> </shutdown-configuration>
An unlimited number of shutdowns can be configured by adding in more entries within the tag. Each entry should be in the format HH:mm. Entries that do not follow the format or that cannot be interpreted by the service will be ignored and an error written to the Event Log on the client machine when the file is read.
Three settings can be defined which alter the behaviour of the user interface.
AllowCancelShutdown – defines whether or not a user is permitted to cancel any configured shutdowns. This option may be required in environments where strict power management policies exist.
AllowAddCustomShutdown – defines whether the options for adding a scheduled shutdown are available to the user.
WakeComputerFromSleep – defines whether or not the service will attempt to wake up the computer to perform the shutdown. If you are happy that a computer is asleep and do not want it to be fully shutdown, then disable this option.
NotifyOnAppStart – specifies whether or not a popup notification of the next configured shutdown will be shown when the user application starts – typically after the have just logged in.
The configuration file is re-read every hour by the service, so changes made using a GPO are reflected quickly. If you remove a shutdown from the configuration file, the shutdown itself will also be removed from the service.
As there is no native ability within a GPO to modify a XML file on a target system, we have to have a copy of the file on the server and use a Group Policy Preference setting to deploy the configuration file to the machines that require it. All shutdowns are configured on a per machine basis. Using Group Policy Preference Targets and filters, different configuration files can easily be applied to large numbers of machines through a very small number of policies.
Waking a Computer From Sleep
Not all devices handle sleep in the same way, and a number of factors can affect whether or not the service is actually able to wake the computer from sleep in order to perform the shutdown. Some factors, we can configure, some require BIOS configuration and some devices don’t appear to handle Wake Timers (the method of waking the computer up) at all.
There are options in the Power Profile within Windows which define whether or not Wake Timers are enabled and can bring the computer out of sleep. These settings can be found in the Advanced Power Scheme configuration in Windows 7. During the installation of the tool, the necessary settings are checked to see if they exist, and are configured to enable wake timers.
The BIOS of the system must also be configured to allow the OS to bring the computer our of sleep. This setting is not able to be controlled by the tool.
Finally, there does appear to be a luck element about this configuration too. My HP workstation can reliably be woken up using a Wake Timer every time that I want it to be, on the contrary, no matter how I configure my Dell Latitude E6430 laptop, I have never managed to get it to successfully wake up. The best way to determine how effective the Wake settings will be in your environment and on the systems that you support will be to test it.
Download & Change Log
The software is available from here:
– Version 2.8
- Fixed false notification popup when waking from sleep
- Fixed false notification message when cancelling the Add New Shutdown form
- Added checks before cancelling a shutdown
- Fixed Show All Shutdowns button action
– Version 2.5
- Fixed bug where the Shutdown Service would crash when cleaning up shutdowns after hibernating
- Check that the Add New Shutdown time is in the future before adding to the list
- Fixed bug that would stop the next shutdown from ever occurring
- Fixed issue with updating items across threads in the Shutdown Service
– Version 2.4
- Better handling of invalid configuration items in the XML file
- Improved handling of service control during installation and upgrade
– Version 2.1
- Significant rewrite
- Support for adding a custom shutdown time
- Ability to control whether shutdowns can be added or cancelled through the configuration file
- Fixed issues with timing when a shutdown has been cancelled
- Fixed issues whether shutdowns would not be called if they fell in to the next day
- Restricted pipe communications so that only the local users can communicate and control the service
- Updated user notifications to remove so ambiguity in the messages
- Improved error handling and logging to the event logging
- Fixed issues with multiple locally logged on users being displayed different shutdown times
- Fixed cancelled shutdowns so that they actually stop when another logged on user requests the shutdown
- Fixed issues with the user interface freezing if communications with the service failed
- Initial public release
This software is provided as-is free of charge. No liability will be taken for any loss of work or data due to a configured shutdown being executed.