Nifty Way to Automatically Run a Windows Script or Program Whenever You Turn Off the PC

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.

Run a script or program at shutdownGroup Policy Editor

  1. To access GPE, open the Run box with the keyboard shortcut Winkey+R.
  2. In the Run box enter “gpedit.msc” (without quotes).
  3. In the left pane of the GPE dialog box under "Computer Configuration", click “Windows Settings”
  4. In the expanded list of Windows settings, click the entry “Scripts (Startup/Shutdown)". (Click the first thumbnail for an example.)
  5. In the right pane, double-click “Shutdown”.Add script
  6. In the dialog box that opens, click the button “Add”. (Click the second thumbnail to see a graphic.)
  7. Browse to the executable file that you want to run at shutdown. Enter any script parameters needed
  8. 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.

Click here for more items like this. Better still, get Tech Tips delivered via your RSS feeder or alternatively, have the RSS feed sent as email direct to your in-box.

 

Share this
4.416665
Average: 4.4 (12 votes)
Your rating: None

Gizmo's Freeware is Recruiting!

Gizmos Needs YouShare your knowledge of free software with millions of Gizmo's readers by joining our editing team.  Details here.