dsoframer控件注册,解注册和检查注册情况

 

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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)使用:

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

  

 

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

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

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

posted @   翻白眼的哈士奇  阅读(1225)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示