How do I restart a COM+ application on a remote server from .NET?

寵の児 提交于 2019-12-23 19:58:04

问题


How do I programmatically restart a COM+ application running on a remote server from code in .NET?


回答1:


You have to use the ComAdmin API through COM interop.

Put a reference on Windows\System32\Com\ComAdmin.dll, then:

COMAdmin.COMAdminCatalog catalog = new COMAdmin.COMAdminCatalogClass();
catalog.Connect(servername);
catalog.ShutdownApplication(AppNameOrAppID);

You can find the ComAdmin reference in MSDN here.

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.

EDIT (some note):

Actually, you CAN write

COMAdmin.COMAdminCatalog catalog = new COMAdmin.COMAdminCatalog();

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()

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.



来源:https://stackoverflow.com/questions/954830/how-do-i-restart-a-com-application-on-a-remote-server-from-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!