You can't do it as a scheduled task but you can run scripts at logoff through Group Policy. If you have an AD domain create a new GPO. If not then you can edit the local policy via GPEDIT.MSC.
The setting is under User configuration-> Windows Settings-> Logoff in both cases.