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

  • 相关阅读:
    hdu-6166(最短路+二进制分组)
    hdu-1238(kmp+枚举)
    hdu-3294(最长回文子串)
    hdu-3068(最长回文子串-manacher)
    二维凸包 Graham扫描算法 +hdu 1392
    经典技术书籍
    hdu 5365 计算几何 给几个点判断是否为正方形
    线性素数筛
    关于大数的题
    树状数组的简介和线段树基础操作
  • 原文地址:https://www.cnblogs.com/teyond/p/UnInstall.html
Copyright © 2011-2022 走看看