VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之C# 从注册表判断指定ocx控件是否已注册

复制代码
 

 

 

/// <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;
}
}

 
复制代码

相关教程