//注册非根目录下在文件
[DllImport(@"ffdshow\ffdshow.ax")]
private static extern void DllRegisterServer();
DllRegisterServer();
//导入注册表
if (File.Exists(@"ffdshow\register.reg"))
{
Process.Start("regedit", string.Format(" /s {0}", @"ffdshow\register.reg"));
}
//软件卸载
DialogResult dia= DevComponents.DotNetBar.MessageBoxEx.Show(null, "重要提醒:软件运行所必须组件丢失,本软件将自动卸载,是否继续?", "警告!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dia == DialogResult.Yes)
{
RegistryKey regKey=Registry.LocalMachine.OpenSubKey (@"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products");
GetProductCode(regKey);
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName =Environment.SystemDirectory +"\\Msiexec.exe";
StartInfo.Arguments = "/X "+_regCode;
StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
StartInfo.UseShellExecute = false;
StartInfo.RedirectStandardError = false;
StartInfo.RedirectStandardInput = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.CreateNoWindow = true;
Process pro = new Process();
pro.StartInfo = StartInfo;
pro.Start();
pro.WaitForExit();
}
private string _regCode = string.Empty;
private void GetProductCode(RegistryKey _registryKey)
{
RegistryKey key = _registryKey;
if (key.SubKeyCount == 0)
{
string[] valueNames = key.GetValueNames();
if (!valueNames.Contains("Contact")) return;
else if (key.GetValue("Contact").ToString().Trim() != "CompanyName") return;
if (!valueNames.Contains("DisplayName")) return;
else if (key.GetValue("DisplayName").ToString().Trim() != "FileName") return;
if (!valueNames.Contains("UninstallString")) return;
else
{
string strtmp = key.GetValue("UninstallString").ToString();
_regCode = strtmp.Substring(strtmp.IndexOf('{'));
}
}
else
{
if (_regCode.Trim() != string.Empty) return;
string[] subKeyNames = key.GetSubKeyNames();
foreach (string str2 in subKeyNames)
{
GetProductCode(key.OpenSubKey(str2));
}
}
}
#endregion