注册flash 为例: 代码比较差 仅供学习参考
/// <summary>
/// 注册组件
/// </summary>
private static void Registor()
{
PrintLog("注册flash");
#if _RELEASE && !_ORG_MANAGER
string ver=GetRegistData("CurrentVersion");
bool flag = true;
if (ver.Length != )
{
string[] vString = ver.Split(',');
if (vString.Length == )
{
int major = ;
int minor = ;
int build = ;
int revision = ; int.TryParse(vString[],out major);
int.TryParse(vString[], out minor);
int.TryParse(vString[], out build);
int.TryParse(vString[], out revision); Version v1 = new Version(, , , );
Version v2 = new Version(major, minor, build, revision);
if (v2>v1)
flag = false;
}
}
if(flag)
{
Registor(@"bin\Flash32.ocx");
}
#endif
} private static void Registor(string filename)
{
try
{
var fi = new FileInfo(filename);
File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\" + fi.Name);
File.Copy(fi.FullName, Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\" + fi.Name);
}
catch (Exception ex)
{
PrintException(ex);
} try
{
var fi = new FileInfo(filename); if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\" + fi.Name))
{
var p = new Process();
p.StartInfo.FileName = "regsvr32.exe";
p.StartInfo.CreateNoWindow = false;
p.StartInfo.Arguments = "/s " + Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\" +
fi.Name;
p.Start();
}
}
catch (Exception ex)
{
PrintException(ex);
}
} private static string GetRegistData(string name)
{
string registData = "";
try
{
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE", false);
RegistryKey aimdir = software.OpenSubKey("Macromedia\\Flashplayer", false);
registData = aimdir.GetValue(name).ToString();
}
catch (Exception)
{
}
return registData;
}