If the COM+ application is running, it will continue to hold the file open. Any time you want to remove components, you should disable and shutdown the application while removing the component, then enable the application again afterwards.
You have to use the ICOMAdminCatalog or ICOMAdminCatalog2 family of interfaces to do this. Any search engine will turn up numerous examples of doing the following tasks in VBScript. I am not aware of any .NET wrapper projects around COM+ administration.
A flow of the logic that I think is a best practice:
- Disable the application
- Shut down the application
- Monitor and wait for active calls to shut down
- Uninstall the component
- Enable the application
You can start the application as well, but it should start automatically with the next call to the application.
Each of these steps uses different aspects of the administration classes, and some of them are already solved as individual answers.
Organization
Before you write COM+ administration code, you should understand the hierarchy of the system. Microsoft has this well documented: http://msdn.microsoft.com/en-us/library/windows/desktop/ms687763%28v=vs.85%29.aspx
Disabling
You will need to fetch the Application from the Applications collection. The property to set is "IsEnabled". Don t forget to save changes after changing the property.
Shutting down
Here s a good answer: How do I restart a COM+ application on a remote server from .NET?
It is safe to call ShutdownApplication on an application that is not running.
Monitoring
You ll need to look for the application in the ApplicationInstances collection. If it is not found, then it must have shut down (or was never running in the first place). If it is found, sleep for an acceptable period of time and look for it again from a refreshed instance of the collection.
Uninstall/Reinstall
You ve got this part solved already.
Enabling
The process of enabling is the same as you followed for disabling the application, but with a different IsEnabled property value.