How many times have you tried to delete a file and only to discover that it locked by some application or service?
The "Handle" tool from Sysinternals is a command line tool that shows you the open handles in your system and allows you to close any selected handle.
There are more tools like Handle that show you open files (like "Process Explorer" also from Sysinternals) but using a command line tool allows you, with proper script, to automate things.
Handle - the command line tool: http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx
Process Explorer - similar functions (and more) with GUI: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx