Have you ever wanted a way to run a program or script automatically when the computer is shut down or when a user logs off? At the end of the day you may want to do some computer housekeeping or back up some regularly used files. Although automatically running a program at startup is easy, how to run something at shutdown is less obvious. It turns out that many Windows versions have a built-in way to do this and this is how it works.
Group Policy Editor
The trick is to use the Windows system tool called the “Group Policy Editor” (GPE). Unfortunately, Microsoft left GPE out of home versions of Windows so this method applies only to versions such as Professional and Enterprise. But it does apply to Windows XP on up, including Windows 8. You may be familiar with GPE since it is a very handy feature with many uses. Its ability to schedule scripts and programs is less well known, however.
GPE is one of the Windows modules known as a Microsoft Management Console and is not listed as a program. Details for using GPE in Windows 7 and 8 are given here. Use in Windows XP is described at this link. It has to be run in an administrative account. Here is the procedure using GPE to schedule something to run at shut down.
- To access GPE, open the Run box with the keyboard shortcut Winkey+R.
- In the Run box enter “gpedit.msc” (without quotes).
- In the left pane of the GPE dialog box under "Computer Configuration", click “Windows Settings”
- In the expanded list of Windows settings, click the entry “Scripts (Startup/Shutdown)". (Click the first thumbnail for an example.)
- In the right pane, double-click “Shutdown”.
- In the dialog box that opens, click the button “Add”. (Click the second thumbnail to see a graphic.)
- Browse to the executable file that you want to run at shutdown. Enter any script parameters needed
- Click “OK”.
Run a script or program when a user logs off
If you prefer to run a program or script only when a particular user logs off, there are settings for individual user accounts. For example, this could be useful to clean up after a child logs off. The procedure is the same as above except that, in step 3 , “Computer Configuration” is replaced by “User Configuration” and in other steps “Shutdown” is replaced by “Logoff”.
This tip is best suited to more experienced PC users. More information about using GPE to schedule scripts can be found at Microsoft,
An alternative method for those who are comfortable with writing scripts is to use a batch file or VBScript containing the desired actions plus a shutdown command at the end.
Get your own favorite tip published! Know a neat tech tip or trick? Then why not have it published here and receive full credit? Click here to tell us your tip.
This tips section is maintained by Vic Laurie. Vic runs several websites with Windows how-to's, guides, and tutorials, including a site for learning about Windows and the Internet and another with Windows 7 tips.