Simple problem: we had to replace the config files for an app that hits the database, pointing it at a CNAME.
However, the file could be in use because the app was running. And the app only loads the file on startup. So we came up with this, which worked quite well. Note that we use WMI (see my other posts on it!) to grab the application info then a WMI method to terminate the app.