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   内涵函数使用方法

dsoframer控件注册,解注册和检查注册情况的更多相关文章

  1. 因为此控件已在 web.config 中注册并且与该页位于同一个目录中

    在web.config文件配置了用户控件 <pages> <controls> <add tagPrefix="my" tagName="l ...

  2. dsoframer控件在64系统上使用问题小汇总

    由于工作中需要,我接触了dsoframer控件,我办公电脑是64系统,在使用时,总是报没有注册类错误.我很是奇怪,dsoframer.ocx控件我都注册过的呀.然后在网上查阅了许多相关资料.悲哀的是, ...

  3. dsoframer控件学习小结(打开WORD,EXCEL等文件)

    根据自己对dsoframer控件的学习,想把dsoframer控件进行简单的包装为C#的usercontrol,大体需要作如下:(创建windows的usercontrol的步骤就不再说了...)我们 ...

  4. C++ CComboBox控件详解

    转载:http://blog.sina.com.cn/s/blog_46d93f190100m395.html C++ CComboBox控件详解 (2010-09-14 14:03:44) 转载▼ ...

  5. IOS—UITextFiled控件详解

    IOS—UITextFiled控件详解 //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGR ...

  6. picker控件详解与使用,(实现省市的二级联动)

    picker控件详解与使用,(实现省市的二级联动) 第一步:新建一个单视图(single view)的工程, 命名为pickerTest,不要勾选下面两个选项,第一个是新版本里面的,第二个是单元测试, ...

  7. Switch控件详解

    Switch控件详解 原生效果 5.x 4.x 布局 <Switch android:id="@+id/setting_switch" android:layout_widt ...

  8. ToolBar控件详解

    ToolBar控件详解 在Activity中添加ToolBar 1.添加库 dependencies { ... compile "com.android.support:appcompat ...

  9. Spinner控件详解

    Spinner控件详解 效果图 修改Spinner样式 在介绍之前,先看一下系统原生的样式 6.x & 5.x系统样式 4.x系统样式 官方文档 XML属性 方法 描述 android:dro ...

  10. Android开发:文本控件详解——TextView(一)基本属性

    一.简单实例: 新建的Android项目初始自带的Hello World!其实就是一个TextView. 在activity_main.xml中可以新建TextView,从左侧组件里拖拽到右侧预览界面 ...

随机推荐

  1. Leetcode之动态规划(DP)专题-121. 买卖股票的最佳时机(Best Time to Buy and Sell Stock)

    Leetcode之动态规划(DP)专题-121. 买卖股票的最佳时机(Best Time to Buy and Sell Stock) 股票问题: 121. 买卖股票的最佳时机 122. 买卖股票的最 ...

  2. 一个提高照片质量的网站和一个改变照片DPI的方法

    相信很多童鞋都有遇到过,碰到一张很喜欢的图片,想用来做背景什么的,蛋似--因为画质太AV了怕引起误会,所以不敢使用!很气--!! 这时大神就会跳出来说,画质不好?PS是用来吃si的么! 我:我才不会用 ...

  3. K/3 Cloud 中FID和FMasterID的区别

    经常会用到,例如物料在多组织情况下. 例如一个物料分配不同组织后,内码FID肯定是不同的,但FMaterId还是一样的,因为是用一个物料. FMASTERID是和物料编码对应的内码,即一个物料编码对应 ...

  4. 记录运行时间 StopWatch

  5. English 邮件

    1.email http://www2.elc.polyu.edu.hk/cill/eiw/e-mail.htm

  6. 【转帖】Office的光荣历史(1)

    Office的光荣历史(1) https://www.sohu.com/a/201410882_657550 微软的第一版本的office 竟然是 给Mac OS 提供的.. 2017-10-31 1 ...

  7. SQL Server 2019 Linux Docker 在主机上以其他非根用户的身份运行容器

    docker logs mssql2019SQL Server 2019 will run as non-root by default.This container is running as us ...

  8. 方格取数--状压DP or 网络流

    题意:http://acm.hdu.edu.cn/showproblem.php?pid=1565 取不相邻的点是权值最大. 这题可以网络流做,暂时先DP一下,网络流明天学一下~~ #define I ...

  9. WebMvcConfigurationSupport跨域和fastjson全局替换

    @Configuration public class WarnWebMvcConfigurationSupport extends WebMvcConfigurationSupport { /** ...

  10. Postgresql explain的analyze和buffers选项

    sql查询分析: 原文地址:https://blog.csdn.net/qq_28893679/article/details/78316283