dsoframer控件注册,解注册和检查注册情况
2024-09-03 06:03:27
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,一下是查找方法
dsoframer.ocx(32位)下载地址:https://pan.baidu.com/s/16Jd60vgU09KYxzOlZsti-A 提取码:7xgh 内涵函数使用方法
最新文章
- Node使用multiparty包上传文件
- 程序员的修养 -- 如何写日志(logging)
- CentOS6.6 kickstart文件
- 前端JSON使用总结
- Python中__init__方法/__name__系统变量讲解
- QTreeView使用点点滴滴
- linux中断--进程上下文和中断上下文
- js柯里化的一个应用
- NVelocity 实例
- Swift之UITabBarController 导航控制器颜色的改变
- Linux - 简明Shell编程07 - 数组(Array)
- javaweb-番外篇-Commons-FileUpload组件上传文件
- 新盘进行LVM的划分
- c++中二级指针的使用场景
- Oracle 语句整理
- 9.22 keep studying
- Android中使用第三方jar包
- EF GroupBy 根据key 分组 再把key求和(取决于每条数据中 arr的条数) arr 中有多少条数据 就把多少个key 加起来
- leetcode-组合总数IV(动态规划)
- Django工程目录结构优化