C# 读取注册表获取本机的全部的typelib信息

根据本机的注册表得出结论

 


 1 public class MyTypeLibInfor
 2     {
 3         public string TypeLibName { get; set; }
 4         public string TypeLibGuid { get; set; }
 5         public string TypeLibWin32FullPath { get; set; }
 6         public string TypeLibWin64FullPath { get; set; }
 7         public string Description { get; set; }
 8         public MyTypeLibInfor(RegistryKey regKey)
 9         {
10             this.TypeLibGuid = regKey.Name;
11             var item = regKey.OpenSubKey(regKey.GetSubKeyNames()[0], false);
12             if (item.GetValue("") != null) this.TypeLibName = item.GetValue("").ToString();
13             if (item.OpenSubKey("0\\win32", false) != null)
14             {
15                 if (item.OpenSubKey("0\\win32", false).GetValue("") != null)
16                 {
17                     this.TypeLibWin32FullPath = item.OpenSubKey("0\\win32", false).GetValue("").ToString();
18                 }
19             }
20             if (item.OpenSubKey("0\\win64", false) != null)
21             {
22                 if (item.OpenSubKey("0\\win64", false).GetValue("") != null)
23                 {
24                     this.TypeLibWin64FullPath = item.OpenSubKey("0\\win64", false).GetValue("").ToString();
25                 }
26             }
27         }
28     }

主函数
 1  private void getAllTypeLibToolStripMenuItem_Click(object sender, EventArgs e)
 2         {
 3             List<MyTypeLibInfor> listTypelibs = new List<MyTypeLibInfor>();
 4             using (var clsidRootKey = Registry.ClassesRoot.OpenSubKey("TypeLib"))
 5             {
 6                 foreach (var typeLibKey in clsidRootKey.GetSubKeyNames())
 7                 {
 8                     var key = clsidRootKey.OpenSubKey(typeLibKey, false);
 9                     if (key != null) listTypelibs.Add(new MyTypeLibInfor(key));
10                 }
11             }
12             if (listTypelibs.Count > 0) MycommonUility.ListClassToExcelSh(listTypelibs);
13         }

 lsit class 转excel导出

 

 1  public static void ListClassToExcelSh<T>(List<T> myList)
 2         {
 3             Excel.Application xlapp = new Excel.Application();
 4             Excel.Workbook wb = xlapp.Workbooks.Add();
 5             Excel.Worksheet ws = (wb.Sheets[1]) as Excel.Worksheet;
 6             Type t = myList[0].GetType();
 7             var pros = t.GetProperties().Where(c => c.DeclaringType.IsPublic).ToArray();
 8             for (int i = 0; i < pros.Length; i++) ws.Cells[1, i + 1] = pros[i].Name;
 9             for (int i = 0; i < myList.Count; i++)
10             {
11                 for (int j = 0; j < pros.Length; j++) ws.Cells[i + 2, j + 1] = pros[j].GetValue(myList[i]);
12             }
13             ws.UsedRange.EntireColumn.AutoFit();
14             xlapp.Visible = true;
15             xlapp.WindowState = Excel.XlWindowState.xlMaximized;
16         }

 

 

 

posted @ 2020-09-03 10:42  南胜NanSheng  阅读(356)  评论(0编辑  收藏  举报