private void LoadLocalServices()
{
List<IGrouping<Guid, COMCLSIDEntry>> clsidsByAppId = m_reg.ClsidsByAppId.ToList();
IDictionary<Guid, COMAppIDEntry> appids = m_reg.AppIDs;
Dictionary<string, ServiceController> services;
try
{
services = ServiceController.GetServices().ToDictionary(s => s.ServiceName.ToLower());
}
catch (Win32Exception)
{
services = new Dictionary<string,ServiceController>();
}
List<TreeNode> serverNodes = new List<TreeNode>();
foreach (IGrouping<Guid, COMCLSIDEntry> pair in clsidsByAppId)
{
if(appids.ContainsKey(pair.Key) && !String.IsNullOrWhiteSpace(appids[pair.Key].LocalService))
{
COMAppIDEntry appidEnt = appids[pair.Key];
string name = appidEnt.LocalService;
if (services.ContainsKey(name.ToLower()))
{
try
{
ServiceController sc = services[name.ToLower()];
string displayName = sc.DisplayName;
if (!String.IsNullOrWhiteSpace(displayName))
{
name = displayName;
}
}
catch (Win32Exception)
{
}
}
TreeNode node = new TreeNode(name);
StringBuilder builder = new StringBuilder();
AppendFormatLine(builder, "AppID: {0}", pair.Key);
if (!String.IsNullOrWhiteSpace(appidEnt.RunAs))
{
AppendFormatLine(builder, "RunAs: {0}", appidEnt.RunAs);
}
node.ToolTipText = builder.ToString();
node.Tag = appidEnt;
int count = pair.Count();
TreeNode[] clsidNodes = new TreeNode[count];
string[] nodeNames = new string[count];
int j = 0;
foreach(COMCLSIDEntry ent in pair)
{
clsidNodes[j] = CreateClsidNode(ent);
nodeNames[j] = ent.Name;
j++;
}
Array.Sort(nodeNames, clsidNodes);
node.Nodes.AddRange(clsidNodes);
serverNodes.Add(node);
}
}
treeComRegistry.Nodes.AddRange(serverNodes.ToArray());
Text = "Local Services";
}