public class DsoframerHelper
{
private static string dsoframerPath = System.Windows.Forms.Application.StartupPath + @"/Plugins/dsoframer.ocx";
private static string sys32Path = @"c:\windows\System32\dsoframer.ocx";//32位系统存放dsoframer.ocx的目录
private static string sys64Path = @"c:\windows\SysWOW64\dsoframer.ocx";//64位系统存放dsoframer.ocx的目录 /// <summary>
/// 判断ocx控件是否注册的
/// </summary>
/// <param name="clsid"></param>
/// <returns></returns>
private static bool IsRegistered(string clsid)
{
String key = String.Format(@"CLSID\{{{0}}}", clsid);
Microsoft.Win32.RegistryKey Regkey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(key);//获取注册key
if (Regkey != null)
if(Regkey != null)
{
if(Regkey.OpenSubKey("InprocServer32").GetValue("") != null)//获取注册路径
return true;
else
return false;
}
else
return false;
} /// <summary>
/// 执行cmd.exe
/// </summary>
/// <param name="cmdExe"></param>
/// <param name="cmdPara"></param>
private static void Cmd(string cmdExe, string cmdPara)
{
using (System.Diagnostics.Process myPro = new System.Diagnostics.Process())
{
myPro.StartInfo.FileName = "cmd.exe";
myPro.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
myPro.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
myPro.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
myPro.StartInfo.RedirectStandardError = true;//重定向标准错误输出
myPro.StartInfo.CreateNoWindow = true;//不显示程序窗口
myPro.StartInfo.Verb="runas";//以管理员的身份打开
myPro.Start();
string strCmd = $@"{cmdExe} {cmdPara} &exit"; //这里使用 & 是批处理命令的符号,表示前面一个命令不管是否执行成功都执行后面(exit)命令
myPro.StandardInput.WriteLine(strCmd);
myPro.StandardInput.AutoFlush = true;
myPro.WaitForExit();//等待程序执行完退出进程
}
} /// <summary>
/// 判断dsoframer是否注册
/// </summary>
/// <returns></returns>
public static bool IsRegisteredDsoframer()
{
return IsRegistered("00460182-9E5E-11d5-B7C8-B8269041DD57");
} /// <summary>
/// 注册dsoframer
/// </summary>
public static void RegisteredDsoframer()
{
if (!File.Exists(dsoframerPath))
return; //将dsoframer.ocx拷贝到系统目录
string sysPath = "";
if (Environment.Is64BitOperatingSystem)
sysPath = sys64Path;
else
sysPath = sys32Path; if (!File.Exists(sysPath))
File.Copy(dsoframerPath, sysPath); Cmd("regsvr32.exe", sysPath);
} /// <summary>
/// 解注册dsoframer
/// </summary>
public static void UnRegisteredDsoframer()
{
Cmd("regsvr32.exe", $@" -u {dsoframerPath}");
}
}

  

注意:如果注册的时候,被杀毒软件阻拦了,会造成注册表中有key没有value的情况。所以注册是否成功需要判断key和value是否都有值才行!!!

(1)准备工作: 

在解决方案下创建Plugins目录,然后将dsoframer.ocx复制到Plugins目录下

(2)使用:

                if (!DsoframerHelper.IsRegisteredDsoframer())
DsoframerHelper.RegisteredDsoframer();

  

检查ocx控件是否注册需要用到clsid,一下是查找方法

查看ocx控件CLSID的方法(转载)

dsoframer.ocx(32位)下载地址:https://pan.baidu.com/s/16Jd60vgU09KYxzOlZsti-A    提取码:7xgh   内涵函数使用方法

最新文章

  1. Node使用multiparty包上传文件
  2. 程序员的修养 -- 如何写日志(logging)
  3. CentOS6.6 kickstart文件
  4. 前端JSON使用总结
  5. Python中__init__方法/__name__系统变量讲解
  6. QTreeView使用点点滴滴
  7. linux中断--进程上下文和中断上下文
  8. js柯里化的一个应用
  9. NVelocity 实例
  10. Swift之UITabBarController 导航控制器颜色的改变
  11. Linux - 简明Shell编程07 - 数组(Array)
  12. javaweb-番外篇-Commons-FileUpload组件上传文件
  13. 新盘进行LVM的划分
  14. c++中二级指针的使用场景
  15. Oracle 语句整理
  16. 9.22 keep studying
  17. Android中使用第三方jar包
  18. EF GroupBy 根据key 分组 再把key求和(取决于每条数据中 arr的条数) arr 中有多少条数据 就把多少个key 加起来
  19. leetcode-组合总数IV(动态规划)
  20. Django工程目录结构优化

热门文章

  1. 两表拼接 pd.concat
  2. Linux服务知识点总结
  3. dfs -cogs 5 P服务点设置
  4. Linux中脚本运行错误(坏的解释器:没有那个文件或目录)
  5. C++学习笔记-STL
  6. Angular中ngx-image-cropper图片裁剪的使用
  7. MySQL_表数据操作
  8. Macaca环境搭建(四)----mac系统macaca安装
  9. PTA(Advanced Level)1083.List Grades
  10. ABP领域层定义仓储并实现