zoukankan      html  css  js  c++  java
  • 导入注册表文件,注册dll

           //注册非根目录下在文件
        [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

  • 相关阅读:
    SERV-U处于“域正离线”怎么办?
    在wampserver3.0.6中配置虚拟主机(设置二级域名)
    解决Win7系统新建选项中无记事本问题
    解决Windows Server 2008 R2安装WAMPSERVER3.0.6问题总结
    php实现定时任务的思路
    https配置for apache
    jquery传值
    有趣的em
    自我感觉良好的配搭
    正则基础整理
  • 原文地址:https://www.cnblogs.com/teyond/p/UnInstall.html
Copyright © 2011-2022 走看看