/***********************
* 说明:注册控件通用类
* 创建人:龚宇超
* 创建日期:2018-05-08
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
***********************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Win32;
using System.Diagnostics;
using System.Security.AccessControl;
using System.Windows.Forms;
namespace Lskj.Util
{
///
/// Class RegControlHelper.
///
public class RegControlHelper
{
///
/// 说明:进行注册
/// 创建人:龚宇超
/// 创建日期:2018-01-29
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
public static bool Registe(string regisFile)
{
bool result = false;
System.Diagnostics.Process p = new Process();
p.StartInfo.FileName = "Regsvr32.exe";
p.StartInfo.Arguments = regisFile+" /s";//路径中不能有空格
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Verb = "runas";
p.Start();
if (p != null && p.HasExited)
{
Int32 exitCode = p.ExitCode;
if (exitCode == 0)
result = true;
}
p.Close();
return result;
}
///
/// 说明:判断注册表是否注册
/// 创建人:龚宇超
/// 创建日期:2018-05-09
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
public static bool IsRegistered(string RegisterId)
{
if (String.IsNullOrEmpty(RegisterId))
return false;
String key = String.Format(@"CLSID\{{{0}}}", RegisterId);
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(key);
return regKey == null ? false : true;
}
///
/// 说明:注册OCX
/// 创建人:龚宇超
/// 创建日期:2018-07-31
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// true if [is register cm capture]; otherwise, false.
public static void IsRegisterOcx(string fileName)
{
Process proc = null;
try
{
//获取文件信息
FileInfo fileInfo = new FileInfo(fileName);
//重新设置该文件的管理员完全控制访问权限
System.Security.AccessControl.FileSecurity fileSecurity = fileInfo.GetAccessControl();
fileSecurity.ResetAccessRule(new FileSystemAccessRule("Administrators", FileSystemRights.FullControl, AccessControlType.Allow));
fileInfo.SetAccessControl(fileSecurity);
proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = fileName;
proc.StartInfo.Arguments = string.Format("10");//this is argument
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.Verb = "runas";
proc.Start();
proc.WaitForExit();
}
catch (Exception ex)
{
}
}
}
}