private void RemoveUninstaller()
 {
     using (RegistryKey key = Registry.LocalMachine.OpenSubKey(UninstallRegKeyPath, true))
     {
         if (key == null)
         {
             return;
         }
         try
         {
             string      guidText = UninstallGuid.ToString("B");
             RegistryKey child    = key.OpenSubKey(guidText);
             if (child != null)
             {
                 child.Close();
                 key.DeleteSubKey(guidText);
             }
         }
         catch (Exception ex)
         {
             throw new Exception(
                       "An error occurred removing uninstall information from the registry.  The service was uninstalled will still show up in the add/remove program list.  To remove it manually delete the entry HKLM\\" +
                       UninstallRegKeyPath + "\\" + UninstallGuid, ex);
         }
     }
 }
Пример #2
0
        private void CreateUninstaller()
        {
            this.BeginInvoke(new Action(() => Status = "Creating Uninstaller ..."));

            using (RegistryKey parent = Registry.LocalMachine.OpenSubKey(
                       @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true))
            {
                if (parent == null)
                {
                    throw new Exception("Uninstall registry key not found.");
                }
                try
                {
                    RegistryKey key = null;

                    try
                    {
                        string guidText = UninstallGuid.ToString("B");
                        key = parent.OpenSubKey(guidText, true) ??
                              parent.CreateSubKey(guidText);

                        if (key == null)
                        {
                            throw new Exception(String.Format("Unable to create uninstaller '{0}\\{1}'", UninstallRegKeyPath, guidText));
                        }

                        Assembly asm = GetType().Assembly;
                        Version  v   = asm.GetName().Version;
                        string   exe = "\"" + asm.CodeBase.Substring(8).Replace("/", "\\\\") + "\"";

                        key.SetValue("DisplayName", "Complete Distribution System");
                        key.SetValue("ApplicationVersion", v.ToString());
                        key.SetValue("Publisher", "Complete Distribution");
                        key.SetValue("DisplayIcon", exe);
                        key.SetValue("DisplayVersion", v.ToString(2));
                        key.SetValue("URLInfoAbout", "http://www.cdsonline.co.za");
                        key.SetValue("Contact", "*****@*****.**");
                        key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
                        key.SetValue("UninstallString", exe + " Uninstall");
                    }
                    finally
                    {
                        if (key != null)
                        {
                            key.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(
                              "An error occurred writing uninstall information to the registry.  The service is fully installed but can only be uninstalled manually through the command line.",
                              ex);
                }
            }
        }
 private void CreateUninstaller()
 {
     using (RegistryKey parent = Registry.LocalMachine.OpenSubKey(UninstallRegKeyPath, true))
     {
         if (parent == null)
         {
             throw new Exception(String.Format("Uninstall registry key '{0}' not found.", UninstallRegKeyPath));
         }
         try
         {
             RegistryKey key = null;
             try
             {
                 string guidText = UninstallGuid.ToString("B");
                 key = parent.OpenSubKey(guidText, true) ??
                       parent.CreateSubKey(guidText);
                 if (key == null)
                 {
                     throw new Exception(String.Format("Unable to create uninstaller '{0}\\{1}'", UninstallRegKeyPath, guidText));
                 }
                 Assembly asm = GetType().Assembly;
                 Version  v   = asm.GetName().Version;
                 string   exe = "\"" + asm.CodeBase.Substring(8).Replace("/", "\\\\") + "\"";
                 key.SetValue("DisplayName", DisplayName);
                 key.SetValue("ApplicationVersion", v.ToString());
                 key.SetValue("Publisher", "B-Line Medical");
                 key.SetValue("DisplayIcon", exe);
                 key.SetValue("DisplayVersion", v.ToString(2));
                 key.SetValue("URLInfoAbout", "http://www.blinemedical.com");
                 key.SetValue("Contact", "*****@*****.**");
                 key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
                 key.SetValue("UninstallString", exe + " /uninstallprompt");
             }
             finally
             {
                 if (key != null)
                 {
                     key.Close();
                 }
             }
         }
         catch (Exception ex)
         {
             throw new Exception(
                       "An error occurred writing uninstall information to the registry.  The service is fully installed but can only be uninstalled manually through the command line.",
                       ex);
         }
     }
 }