I have had a long couple of weeks looking into an issue where logoff scripts do not run with XenApp 6.5 published applications or with Windows Server 2008 R2 RemoteApp. Logoff scripts work perfectly from a published desktop, or if the user is added to the local Administrators or Power Users group. To make troubleshooting more challenging, sometimes logoff scripts will work.... just sometimes.
The issue appears to be something to do with wfshell.exe as wfshell.exe hangs at logoff for 10 seconds and if an administrator terminates the users wfshell.exe process the logoff scripts run as expected. A fix suggested in the Citrix forums is to add wfshell.exe to LogoffCheckSysModules as described in CTX891671, but this did not work for me.
I ended up rebuilding a XenApp 6.5 server from scratch for the client who was experiencing this issue and the problem went away, so I know it was something installed which was causing the issue but I could not track down the culprit. The looming "solution" was to rebuild the entire farm! Which I was understandably not that happy with, so I decided to log a case with Citrix who ended up providing a workaround which I have successfully tested.
Add wfshell.exe to the list of processes RDS may safely terminate by adding an entry to:
wfshell.exe = 0 (REG_DWORD)
I pushed this entry out to the farm using Group Policy Preferences which is easy, and ensures the setting will always apply to all farm servers.