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)
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.