So the recent postings of the Ninite scripts got me to thinking about how to handle the locked files on Terminal Servers to be able to utilize these scripts. I realized in fact that there are number of times for a terminal server that it would be nice to be able to have some specific things happen before and after doing maintenance on a terminal server, for example when doing patches, or running icsweep to clean out temporary internet files for all users. With all of that in mind, I came up with the following two scripts. Note that for the first one you will need to download the TSLogoff.exe utilty from Ctrl-Alt-Del Consultancy. http://www.ctrl-alt-del.com.au/CAD_TSUtils.htm, and upload this to your server, then correct the path in the Write File portion of my script. Also note that I have not yet had a chance to test these on a 2008 terminal server, so I cannot swear that they work 100% there.
The pre-maintenance script basically checks to see if there are any users logged on, it then disables logons on the server.
If there are any active logged on users, it then notifies any logged in users that the system will be going down for maintenance in 10 minutes and will be down for at least an hour. After pausing for 10 minutes, it will then logoff any remaining user sessions.
The post maintenance script simply re-enables logons on the server.