如何从.NET远程服务器上重新启动COM +应用程序? [英] How do I restart a COM+ application on a remote server from .NET?
问题描述
如何以编程方式从远程服务器上运行的COM +应用程序重新启动.NET中的代码?
How do I programmatically restart a COM+ application running on a remote server from code in .NET?
推荐答案
通过COM interop使用ComAdmin API。
You have to use the ComAdmin API through COM interop.
在Windows \System32\Com\ComAdmin.dll上添加引用,然后:
Put a reference on Windows\System32\Com\ComAdmin.dll, then:
COMAdmin.COMAdminCatalog catalog = new COMAdmin.COMAdminCatalogClass();
catalog.Connect(servername);
catalog.ShutdownApplication(AppNameOrAppID);
您可以在MSDN 这里。
这是一个COM API,例如。你不能实例化一个COMAdminCatalog,因为它是一个接口,而不是一个类,所以你必须使用COMAdminCatalogClass来创建一个新的实例。使用Visual Studio的对象浏览器在COMAdmin命名空间中查找这些陷阱。
It's a COM API, and kind of wierd. Eg. you cannot instantiate a COMAdminCatalog, because it's an interface, not a class, so you have to use COMAdminCatalogClass to create a new instance. Use Visual Studio's Object Browser to look around in the COMAdmin namespace to find out these kinds of pitfalls.
编辑(注意):
其实,你可以写
COMAdmin.COMAdminCatalog catalog = new COMAdmin.COMAdminCatalog();
这是令人惊讶的,因为COMAdminCatalog是一个接口。但它必须是VStudio或C#编译器的伎俩,因为生成的程序集包含以下IL:
and it works which is surprising because COMAdminCatalog is an interface. But it must be a trick of VStudio or the C# compiler, because the resulting assembly contains the following IL:
newobj instance void [Interop.COMAdmin]COMAdmin.COMAdminCatalogClass::.ctor()
所以它以某种方式发现COMAdminCatalogClass必须实例化,这是奇怪的,有点混乱了。如果有人知道如何发生,请注释。
So it somehow found out that the COMAdminCatalogClass must be instantiated, which is strange enough and a bit confusing too. If someone knows how it happens please comment.
这篇关于如何从.NET远程服务器上重新启动COM +应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!