注意

COM组件注册到注册表中的位置,是CLSID还是TypeLib

注册方法

代码执行

//声明注册方法
[DllImport("C:\\Windows\\barcodex.ocx")]
public static extern int DllRegisterServer();//注册时用
//DLL注册
int i = DllRegisterServer();
if (i >= 0)
{
  return true;
}
else
{
  return false;
}

调用控制台执行

string file="";//ocx的文件名称
string fileFullName = "\"" + file + "\"";
System.Diagnostics.Process p = System.Diagnostics.Process.Start("regsvr32", fileFullName + " /s");
 

反注册(卸载)方法

代码执行

//声明注册方法
[DllImport("C:\\Windows\\barcodex.ocx")]
public static extern int DllUnregisterServer();//取消注册时用
//DLL反注册
int i = DllUnregisterServer();
if (i >= 0)
{
  return true;
}
else
{
  return false;
}

调用控制台执行

string file="";//ocx的文件名称
string fileFullName = "\"" + file + "\"";
System.Diagnostics.Process p = System.Diagnostics.Process.Start("regsvr32", fileFullName + " /s /u");
 

检测是否安装的方法

注册在CLSID目录下

String clsid="";//ocx组件的ClassID,不会重复
//设置返回值
Boolean result = false;
String key = String.Format(@"CLSID\{0}", clsid);//注意{},设置的clsid变量的id必须带{}
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(key);
if (regKey != null)
{
  result = true;
}
return result;
返回的regKey对象不为null,则已经表示安装。

注册在TypeLib目录下

String clsid="";//ocx组件的ClassID,不会重复
//设置返回值
Boolean result = false;
//检查方法,查找注册表是否存在指定的clsid
String key = String.Format(@"TypeLib\{0}", clsid);//注意{},设置的clsid变量的id必须带{}
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(key);
if (regKey != null)
{
  result = true;
}
return result;
 

最新文章

  1. visual studio 两个以上sln 引用同一个project ,生成时会改变projectguid问题
  2. 8.31 js基础总结1
  3. tomcat开机启动
  4. 学习WPF——WPF布局——了解布局容器
  5. SQL compute by 的使用
  6. 【CodeForces 621B】Wet Shark and Bishops
  7. poj 3164 最小树形图
  8. 代码优化—From <effective C++>
  9. Hadoop开发环境搭建
  10. Spring AOP在pointcut expression解析表达式 并匹配多个条件
  11. linux ip 转发设置 ip_forward
  12. 【莫比乌斯反演】BZOJ3309 DZY Loves Math
  13. Spring Boot笔记七:扩展Spring MVC
  14. ionic使用iframe时无法显示网页或报错
  15. laravel的seeder数据填充
  16. 使用Android绘图技术绘制一个椭圆形,然后通过触摸事件让该椭圆形跟着手指移动
  17. 802.11ax前瞻4:802.11ax与HiperLan
  18. .Protobuf,GRpc,Maven项目出现UnsatisfiedDependencyException、ClassNotFoundException、BuilderException等异常
  19. 关于 Chrome Console 查看DOM详情细节的奇思淫巧
  20. MySQL:入门

热门文章

  1. Java基础教程——运算符
  2. 关于深度学习之中Batch Size的一点理解(待更新)
  3. 冲刺随笔——Day_Three
  4. JZOJ8月8日提高组反思
  5. 修改MongDB的数据类型
  6. 2019 ACM/ICPC North America Qualifier G.Research Productivity Index(概率期望dp)
  7. 喝完可乐桶后程序员回归本源,开源Spring基础内容
  8. 第1.2节 Python学习环境的使用
  9. PyQt(Python+Qt)学习随笔:Action功能详解及Designer中的操作方法
  10. PyQt(Python+Qt)学习随笔:toolButton的popupMode属性