Scripting through the group policy manager works, here's how you do it;
Prepare your script (must be either a bat or exe)
Start Group policy --- at the run command (Start - Run) type gpedit.msc
Open User Configuration then window settings.
Then Scripts (Logon/Logoff)
Click on Logoff Click Properties
Add whatever you want to run here (can also take parameters)