zoukankan      html  css  js  c++  java
  • 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         }
  • 相关阅读:
    编程语言
    俄罗斯方块
    四则运算
    2019-2020-1 20191312《信息安全专业导论》第七周学习总结
    20191312-获奖感想与学习心得
    2019-2020-1学期 20192428 《网络空间安全专业导论》第九周小组讨论
    2019-2020-1学期 20192428 《网络空间安全专业导论》第九周学习总结
    2019-2020-1学期 20192428 第八周作业——小学四则运算实践
    2019-2020-1学期 20192428《网络空间安全专业导论》第八周学习总结
    2019-2020-1学期 20192428 《网络空间安全专业导论》第七周学习总结
  • 原文地址:https://www.cnblogs.com/NanShengBlogs/p/13606295.html
Copyright © 2011-2022 走看看