zoukankan      html  css  js  c++  java
  • 获取本机的com对象的progid和类型库的位置

     1        StreamWriter sw = new StreamWriter(@"c:123.csv");
     2             string[] strArr = Registry.ClassesRoot.GetSubKeyNames();
     3             sw.WriteLine($"Class Name,CLSID,CurVer,TypeLibGuid,TypeLibName,TypeLibWin32Path,TypeLibWin64Path");
     4             foreach (var strKeyName in strArr)
     5             {
     6                 var key = Registry.ClassesRoot.OpenSubKey(strKeyName, false);
     7                 int icount = key.GetSubKeyNames().Count(c => c == "CLSID" || c == "CurVer");
     8                 if (icount == 2)
     9                 {
    10                     var CLSID = key.OpenSubKey("CLSID", false).GetValue("");
    11                     string _clsid = CLSID == null ? "N.A." : CLSID.ToString();
    12                     var CurVer = key.OpenSubKey("CurVer", false).GetValue("");
    13                     string _curVer = CurVer == null ? "N.A." : CurVer.ToString();
    14                     string _typeLibGuid = string.Empty;
    15                     string _typeLibName = string.Empty;
    16                     string _typeLibWin32Path = string.Empty;
    17                     string _typeLibWin64Path = string.Empty;
    18                     if (CLSID != null)
    19                     {
    20                         var keyTypeLib = Registry.ClassesRoot.OpenSubKey("CLSID\" + CLSID.ToString(), false);
    21                         if (keyTypeLib != null)
    22                         {
    23                             var typeLibGuid = keyTypeLib.OpenSubKey("TypeLib", false);
    24                             if (typeLibGuid != null)
    25                             {
    26                                 if (typeLibGuid.GetValue("") != null) _typeLibGuid = typeLibGuid.GetValue("").ToString();
    27                                 {
    28                                     var keyTypeLib1 = Registry.ClassesRoot.OpenSubKey("TypeLib\" + _typeLibGuid, false);
    29                                     if (keyTypeLib1 != null)
    30                                     {
    31                                         var typeLibNameKey = keyTypeLib1.OpenSubKey(keyTypeLib1.GetSubKeyNames()[0], false);
    32                                         if (typeLibNameKey != null)
    33                                         {
    34                                             var typeLibNameValue = typeLibNameKey.GetValue("");
    35                                             if (typeLibNameValue != null)
    36                                             {
    37                                                 _typeLibName = typeLibNameValue.ToString();
    38                                             }
    39                                             if (typeLibNameKey.SubKeyCount > 0)
    40                                             {
    41                                                 var libPathKey = typeLibNameKey.OpenSubKey(typeLibNameKey.GetSubKeyNames()[0], false);
    42                                                 if (libPathKey != null)
    43                                                 {
    44                                                     foreach (var item in libPathKey.GetSubKeyNames())
    45                                                     {
    46                                                         if (item == "win32")
    47                                                         {
    48                                                             var win32key = libPathKey.OpenSubKey("Win32", false);
    49                                                             if (win32key != null)
    50                                                             {
    51                                                                 var win32Value = win32key.GetValue("");
    52                                                                 if (win32Value != null) _typeLibWin32Path = win32Value.ToString();
    53                                                             }
    54                                                         }
    55                                                         if (item == "win64")
    56                                                         {
    57                                                             var win64key = libPathKey.OpenSubKey("Win64", false);
    58                                                             if (win64key != null)
    59                                                             {
    60                                                                 var win64Value = win64key.GetValue("");
    61                                                                 if (win64Value != null) _typeLibWin64Path = win64Value.ToString();
    62                                                             }
    63                                                         }
    64                                                     }
    65                                                 }
    66                                             }
    67                                         }
    68                                     }
    69                                 }
    70                             }
    71                         }
    72                     }
    73                     sw.WriteLine($"{Path.GetFileName(key.Name)},{_clsid},{_curVer},{_typeLibGuid},{_typeLibName},{_typeLibWin32Path},{_typeLibWin64Path}");
    74                 }
    75             }
    76             sw.Close();
    77             Console.WriteLine("ok");
    78             Console.ReadKey();

    不是很完整,有些程序不按照常规思路出牌,注册表到处放。。。。。。。

    这写classname可用于vb或者c#创建对象,实现后绑定编程操作

     .net方式调用

    vba/vb方式调用

     

  • 相关阅读:
    位运算及其妙用
    Ubuntu 下的Python开发 mysqlclient安装失败问题解决,亲测有效
    Ubuntu "sudo apt update"失败的问题可以这样解决
    青魔法-驭虫术(不定时更新)
    白魔法安全课(持续更新)
    空间魔法-Mysql(持续更新)
    时间魔法-Git(持续更新)
    仪式魔法——区块链(持续更新)
    Web圣堂幻术VUE不定时更新)
    影魔法 Shell 与 Dos(持续更新)
  • 原文地址:https://www.cnblogs.com/NanShengBlogs/p/13620929.html
Copyright © 2011-2022 走看看