Run a script just before shutdown or reboot on Windows Home edition

I need to run a script when the computer shuts down or restarts to remove some files. I know there is a registry key for autorun.. but I couldn't find something for shutdown/reboot.

[update] I want to do this on Windows 7 Home edition, so I don't have the group policy editor.


The easiest way to do this is with a local group policy.

To do this, go to your local group policy editor (Click Start, type gpedit.msc in the Start Search box, and then press ENTER.)

Once this is loaded, go to the following path: Computer Configuration > Windows Settings > Scripts (Startup/Shutdown) > Shutdown (See Below)

enter image description here

Within here, you can choose to select scripts which will run on your machine as part of startup/shutdown. You can also follow the User Config > Windows Settings > Scripts (Logon/Logoff) to setup scripts which run at logon and logoff.

The differences are:

Startup Runs before a user logs on. Startup scripts execute as the local system account

Logon Runs as soon as a user has entered their password. This executes as the user who is logging on.

Logoff Runs as the users session is logging off (whether shutting down or logging off to change user) and executes as the user logging off

Shutdown Runs after logoff and only as part of the machine shutting down. This runs as the local system account.

Hope this helps.


This the path of registry

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

or alternatively

Launch the Group Policy Editor by clicking Start, then type gpedit.msc and hit Enter. Now navigate to the

User Configuration > Windows Settings > Scripts(Log on/Log off)

option.

Add your script there.

Check this for home edition:

To open the Local Group Policy Editor as an MMC snap-in

Open MMC. (Click Start , click in the Start Search box, type mmc , and then press ENTER .)
On the File menu, click Add/Remove Snap-in .
In the Add or Remove Snap-ins dialog box, click Group Policy Object Editor , and then click Add .
In the Select Group Policy Object dialog box, click Browse .
Click This computer to edit the Local Group Policy object, or click Users to edit Administrator, Non-Administrator, or per-user Local Group Policy objects.
Click Finish .