data-ad-format="horizontal">

Download this tool with source (ZIP)

Renow1

Reboot Now or it’s short name ReNow, is an application that runs silently (in the system tray) of a Windows PC and reboots the computer when a pre-configured time is reached. The utility has a configuration window that lets you change the time setting.

ReNow keeps track of its settings inside of a small INI file in the local directory of the application. The location of the INI file allows for as much portability as possible by creating or using the file locally. This INI file contains only one setting that relates to the time  ReNow will reboot the computer. When  ReNow first runs, it displays the default or preconfigured time in the to left hand corner of the window. This time can be set by placing the hour, minute and seconds, as well as the AM/PM label and choosing the set button.  ReNow will then use the new time to reboot the computer.

Renow2

Upon launch,  ReNow runs in the system tray. To display the main window of  ReNow double-click on ReNow’s system tray icon that appears as a small black link. Exiting the tool is done by way of right-clicking ReNow’s system tray icon and choosing “Exit”.

Why Renow?

Renow3

Besides the obvious way this would annoy someone with a constant reboot at the same time of the day, the greater use for this tool lies in the ability to schedule Windows restarts on a machine that might be running an important service. Windows tends to degrade its performance over time as it runs non stop. If you wish to have a Windows client-based (98, XP, 7 or 8) computer setup to run a specific service (DNS possibly, or routing), you would want to keep the computer’s Operating System running as clean as often as possible. Rebooting your server once per day would achieve these results.

Under the hood

ReNow was written and compiled on Delphi 6, and makes use of three main components, TpopupmenuTtimer, and TmdTray. Tpopupmenu and Ttimer are both built-in to Delphi and TmdTray (Copyright 1997-98 by Martin Djernµs) is a third party component. For your convenience, I have added the TmdTray component to the source code in a zip file called tray14.zip. You can get more details about that component and it’s author in that file.

To achieve the automatic tray positioning of the main Form, I loaded the main form the project (renow.dpr) and then hid Form1 using the following command:

ShowWindow(Application.Handle,SW_HIDE);

The second setting to achieve this, was to make sure the  TmdTray component was active when the application runs. This makes ReNow appear to be hidden, but a simple double-click of the tray icon will execute Form1.Show. Writing to INI files requires the inclusion of the inifiles unit in your uses clause. This unit contains a plethora of useful utilities for readying and writing to INI files. One of the harder things I needed to do, was to test for a time frame. Since I could not just say “if the time is 6:00:00 AM” and have ReNow catch the time exactly (your dealing with milliseconds). The best way was to give a little range to make sure I catch the time. To make this work, I had to take the time string and add a minute (or whatever you think works). The following code does the job:

Renow4

stime represents the starting time and is directly read from the INI file. etime is the end time (of the range) and will be the same as stime + 1 minute. atime and atime in this snippet of code are temporary variables (string and integer) to allow me to modify the value I needed and insert it back into etime. I could have done this in less lines, but to make it easier to follow, I decided to use more. The final result is to test to make sure the time is between the 6:00:00AM start time and 6:01:00AM end time. This will loop over and over for one minute, but since we are rebooting, the process will die anyway. You may want to add an Application.Terminate; statement after the reboot to see how the application runs.

Rebooting the computer makes use of the API function ExitWindowsEx(). Details of this function are provided on the MSDN SDK site. ReNow calls the ExitWindowsEx() function in the following way:

Renow5

ExitWindowsEx(EWX_REBOOT,0);

The rest of the application is based on making it more useable. The main window gives the user the ability to hide (Form1.Hide) the main window as well as set (Save the time entered to the application’s INI file. Much of the writing of data to the INI files can be seen by looking at the code in Button2Click.

ReNow has been checked for viruses with VirusTotal’s database current as of August 28, 2012. If you would like to see that report, click here.

If you have any thoughts or ideas, please let me know. I’m always interested in thoughts or ideas on how to make this more useful.