Running a batch file on logoff

Solution 1:

This should do the trick. Save as a REG file and import, unless that is blocked as well. This effectively creates a logoff script entry.

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0\0]
"Script"="H:\your-script-here.bat"
"Parameters"=""
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00 ,00,00,00,00,00

Save your script to do the copy under the root of your H: drive.

Solution 2:

Another similar option to what Tim Brigham already suggested is to save the text below as a .reg file:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Logoff\0]
"GPO-ID"="LocalGPO"
"SOM-ID"="Local"
"FileSysPath"="C:\Windows\System32\GroupPolicy\User"
"DisplayName"="Local Group Policy"
"GPOName"="Local Group Policy"
"PSScriptOrder"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Logoff\0\0]
"Script"="H:\yourScriptFileName.bat"
"Parameters"=""
"IsPowershell"=dword:00000000
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

This is similar to doing it yourself from the Group Policy Editor tool (gpedit.msc).

Solution 3:

you can put that line at the end of your batch file

shutdown -l

this will log you off as soon as the script is done