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 @   南胜NanSheng  阅读(372)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示