Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is there a way to run a batch script on logoff or shutdown in windows 7 home premium?

[edit] to add a bit of context, im looking to delete everything from my downloads folder when i logoff, so unless someone knows a different way of achieving this?


share|improve this question
Sadly, without the group policy editor i don't think there is an easy way to make it work. – bubu Jun 8 '10 at 17:38

Task Scheduler? Create a new task, and have at least one of the trigger(s) be "At log on".

share|improve this answer
+1 for Task Scheduler. You can set permissions and even have it run as Admin for those UAC enabled machines. – Doltknuckle Jun 8 '10 at 21:30
the OP wants to run a script on logoff though, not logon. – Om Nom Nom Jun 8 '10 at 22:20
To add a bit of context, im wanting to delete everything out of my downloads folder when i logoff. – richzilla Jun 8 '10 at 22:35
In that case, why not just install Sandboxie and sandbox the downloads folder, then set it to clear on log off (99% sure thats an option) – Hello71 Jun 9 '10 at 1:08

This may not be the type of solution you are looking for, but you can just use the batch script itself to shutdown or log off using the shutdown command.

C:\ >help shutdown Usage: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f] [/m \computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]

/l         Log off. This cannot be used with /m or /d options.
/s         Shutdown the computer.

Just put this command at the end of your script, maybe with a timer.

share|improve this answer

If you have a program such as acronis backup on your PC, you could schedule it to backup on shutdown, and include your bat file in the pre or post process option. I used this method to alter the contents of text file on a remote server from ON to OFF.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.