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

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM