如何获得com +应用程序的所有com +组件的列表?

时间:2012-10-04 10:52:27

标签: c# asp.net windows .net-4.0 com+

我正在尝试使用c#和ASP.NET来使用COM +。我一直关注example,但其中一部分失败了。

dynamic oCatalog = Activator.CreateInstance(Type.GetTypeFromProgID("ComAdmin.COMAdminCatalog"));
/* Get the Applications collection and populate it */
dynamic applicationInstances = oCatalog.GetCollection("Applications");
applicationInstances.Populate();
foreach (dynamic applicationInstance in applicationInstances)
    {
        Response.Write("<p>" + applicationInstance.Name.ToString() + "-" + applicationInstance.Key.ToString() + "</p>");
        dynamic objComponents = oCatalog.GetCollection("Components", applicationInstance.Key);
        objComponents.Populate();
        foreach(dynamic Components in objComponents)
        {
            Response.Write("<p>" + Components.Name.ToString() + "</p>");
        }           
    }

当调用上述调用oCatalog.GetCollection(“Components”,applicationInstance.Key)时,我收到错误:

  

System.Reflection.TargetParameterCountException:调用时出错   GetCollection。

如何获取应用程序实例中当前组件的列表?

1 个答案:

答案 0 :(得分:7)

您需要向“应用程序”集合询问特定应用程序的组件:

ICOMAdminCatalog2 oCatalog = (ICOMAdminCatalog2) Activator.CreateInstance(Type.GetTypeFromProgID("ComAdmin.COMAdminCatalog"));

ICatalogCollection applications = oCatalog.GetCollection("Applications");
applications.Populate();
foreach (ICatalogObject applicationInstance in applications)
{
    ICatalogCollection comps = applications.GetCollection("Components", applicationInstance.Key);
    comps.Populate();
    foreach (ICatalogObject comp in comps)
    {
        Console.WriteLine("{0} - {1}", comp.Name, comp.Key);
    }
}

在此处查看示例:http://msdn.microsoft.com/en-us/library/windows/desktop/ms686093(v=vs.85).aspx