zoukankan      html  css  js  c++  java
  • dsoframer控件注册,解注册和检查注册情况

     

      

        public class DsoframerHelper
        {
            private static string dsoframerPath = System.Windows.Forms.Application.StartupPath + @"/Plugins/dsoframer.ocx";
            private static string sys32Path = @"c:windowsSystem32dsoframer.ocx";//32位系统存放dsoframer.ocx的目录
            private static string sys64Path = @"c:windowsSysWOW64dsoframer.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   内涵函数使用方法

  • 相关阅读:
    MySQL二进制文件(binlog)
    Linux命令 find和mv的结合使用:查找文件,移动到某个目录
    必会的Linux命令
    Linux kill -9 和 kill -15 的区别
    ansible-playbook 修改主机的host解析
    基于mssql 触发器的访问权限设置
    一个简单的启停服务脚本
    Redis protected-mode属性解读
    Nginx内置变量
    haproxy—TCP负载均衡
  • 原文地址:https://www.cnblogs.com/yaosj/p/10877384.html
Copyright © 2011-2022 走看看