System.EnterpriseServices.RegistrationHelper 不释放文件

发布于 2024-08-11 06:53:28 字数 538 浏览 2 评论 0原文

我们开发了一个小型 MMC 管理单元,用于安装应用程序的各种组件。特别是,它使用 System.EnterpriseServices.RegistrationHelper 向 COM+ 注册 .NET 程序集。逻辑很简单:首先卸载现有程序集,然后复制新文件,然后安装新程序集。代码如下所示:

if (File.Exists(destination))
{
   try
    {
       new RegistrationHelper().UninstallAssembly(destination, ComPlusHelper.ApplicationName);
    }
    catch (Exception ex)
    {
        Log.LogError(...);
    }
}
File.Copy(source, destination, true);

但是,File.Copy 调用失败,并显示错误“进程无法访问文件 xxxx,因为它正在被另一个进程使用”。我花了一天时间阅读 MSDN 并谷歌搜索,但找不到解决方案。

有人有什么建议吗?

We developed a small MMC snap-in that installs various components of the application. In particular, it registers .NET assemblies with COM+ using System.EnterpriseServices.RegistrationHelper. The logic is simple: first, uninstall existing assembly, then copy new file over, then install the new assembly. The code looks like this:

if (File.Exists(destination))
{
   try
    {
       new RegistrationHelper().UninstallAssembly(destination, ComPlusHelper.ApplicationName);
    }
    catch (Exception ex)
    {
        Log.LogError(...);
    }
}
File.Copy(source, destination, true);

However, the File.Copy call fails with the error "The process cannot access the file xxxx because it is being used by another process". I spent a day reading MSDN and googling, but couldn't find a solution.

Does anyone have any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铁轨上的流浪者 2024-08-18 06:53:28

如果 COM+ 应用程序正在运行,它将继续保持文件打开。任何时候您想要删除组件时,都应该在删除组件时禁用并关闭应用程序,然后再次启用应用程序。

您必须使用 ICOMAdminCatalog 或 ICOMAdminCatalog2 系列接口来执行此操作。任何搜索引擎都会找到大量使用 VBScript 执行以下任务的示例。我不知道有任何围绕 COM+ 管理的 .NET 包装器项目。

我认为最佳实践的逻辑流程:

  1. 禁用应用程序
  2. 关闭应用程序
  3. 监视器并等待主动调用来关闭
  4. 卸载组件
  5. 启用应用程序

您也可以启动应用程序,但它应该自动启动下次调用应用程序。

每个步骤都使用管理类的不同方面,其中一些已经作为单独的答案得到解决。

组织

在编写 COM+ 管理代码之前,您应该了解系统的层次结构。微软对此有详细记录: http://msdn.microsoft.com/en-us/library/windows/desktop/ms687763%28v=vs.85%29.aspx

禁用

您将需要从应用程序集合中获取应用程序。要设置的属性是“IsEnabled”。更改属性后不要忘记保存更改。

关闭

这是一个很好的答案:如何从 .NET 重新启动远程服务器上的 COM+ 应用程序?

调用 ShutdownApplication 是安全的在未运行的应用程序上。

监控

您需要在 ApplicationInstances 集合中查找应用程序。如果没有找到,那么它一定已经关闭(或者一开始就没有运行过)。如果找到,则休眠一段可接受的时间,然后从刷新的集合实例中再次查找。

卸载/重新安装

您已经解决了这部分问题。

启用

启用过程与禁用应用程序所遵循的过程相同,但 IsEnabled 属性值不同。

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:

  1. Disable the application
  2. Shut down the application
  3. Monitor and wait for active calls to shut down
  4. Uninstall the component
  5. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文