/// <summary> /// 注册控件 /// </summary> /// <returns></returns> public bool RegControl() { try { //判断该控件是否已经注册 if (!CheckRegistredOcx(@"CLSID\{00460182-9E5E-11D5-B7C8-B8269041DD57}")) { string sPath = Path.Combine(WorkSpace.PublicDirectory, "dsoframer.ocx"); if (!File.Exists(sPath)) return false; Process p = new Process(); p.StartInfo.FileName = "Regsvr32.exe"; p.StartInfo.Arguments = "/s " + sPath; p.Start(); } return true; } catch (Exception ex) { Logger.Write(LoggerLevel.ERROR, "注册dsoframer.ocx失败" + ex.Message, ex.StackTrace); return false; } } /// <summary> /// 检测ocx是否注册 /// </summary> /// <param name="ClassId"></param> /// <returns></returns> private bool CheckRegistredOcx(string ClassId) { Microsoft.Win32.RegistryKey Regkey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ClassId); if (Regkey != null) { string res = Regkey.OpenSubKey("InprocServer32").GetValue("").ToString(); Logger.Write(LoggerLevel.ERROR, "已注册dsoframer.ocx控件", "注册路径:" + res); return true; } else { Logger.Write(LoggerLevel.ERROR, "未注册dsoframer.ocx控件", ""); return false; } }