Server Fault is a question and answer site for system and network administrators. 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

How do I run a script each time I unlock my Windows 7 session?

So, if I lock my session and then log in again, I want the script to run.

Do login scripts configured in the Group Policy do this or will they only work the first time?

share|improve this question
up vote 9 down vote accepted

Scheduled Tasks is what you need. You can set a trigger for both workstation lock and workstation unlock. If you need to deploy it out to more machines, use SCHTASKS.EXE (provided with windows).

Hope that helps

share|improve this answer
Cool. I didn't even know that was an option in Windows 7. It used to be you had to write a winlogon notification app and register it with the system to be triggered on shell change between the desktop and the lock screen. – BoxerBucks Jun 4 '10 at 17:07
+1 - For someone just getting ready to roll out Win 7 that's real handy to know. – John Gardeniers Jun 5 '10 at 21:30
BoxerBucks: Will you release the source for that? – mbrownnyc Sep 4 '12 at 12:50

Group Policy login scripts only process when you first logon. If you only reboot once a month and just keep locking/unlocking, login scripts will run once a month for you.

share|improve this answer
but task scheduler can run tasks every computer unlock – Lưu Vĩnh Phúc Mar 23 at 2:46

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.