2012-10-04 79 views
2

我正在嘗試使用c#和ASP.NET來使用COM +。我一直在關注example,但其中一部分失敗。如何獲得com +應用程序的所有com +組件的列表?

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(「組件」,applicationInstance.Key)被稱爲我得到的錯誤:

System.Reflection.TargetParameterCountException: Error while invoking GetCollection.

我如何可以在應用程序獲取當前的組件列表實例?

回答

5

你要問的組件的「應用程序」收集的具體應用:

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