Example #1
0
        /// <include file='doc\EventLogInstaller.uex' path='docs/doc[@for="EventLogInstaller.Uninstall"]/*' />
        /// <devdoc>
        /// Called to remove the event log source from the machine.
        /// </devdoc>
        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
            if (UninstallAction == UninstallAction.Remove)
            {
                Context.LogMessage(Res.GetString(Res.RemovingEventLog, Source));
                if (EventLog.SourceExists(Source, "."))
                {
                    if (string.Compare(Log, Source, true, CultureInfo.InvariantCulture) != 0)   // If log has the same name, don't delete the source.
                    {
                        EventLog.DeleteEventSource(Source, ".");
                    }
                }
                else
                {
                    Context.LogMessage(Res.GetString(Res.LocalSourceNotRegisteredWarning, Source));
                }

                // now test to see if the log has any more sources in it. If not, we
                // should remove the log entirely.
                // we have to do this by inspecting the registry.
                RegistryKey key = Registry.LocalMachine;
                if (key != null)
                {
                    key = key.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\EventLog\\" + Log, false);
                }
                if (key != null)
                {
                    string[] keyNames = key.GetSubKeyNames();
                    if (keyNames == null || keyNames.Length == 0 ||
                        (keyNames.Length == 1 && string.Compare(keyNames[0], Log, true, CultureInfo.InvariantCulture) == 0) // the only key has the same name as log
                        )
                    {
                        Context.LogMessage(Res.GetString(Res.DeletingEventLog, Log));
                        // there are no sources in this log. Delete the log.
                        EventLog.Delete(Log, ".");
                    }
                }
            }
            // otherwise it's UninstallAction.NoAction, so we shouldn't do anything.
        }
Example #2
0
 /// <summary>Restores the computer to the state it was in before the installation by rolling back the event log information that the installation procedure wrote to the registry.</summary>
 /// <param name="savedState">An <see cref="T:System.Collections.IDictionary" /> that contains the pre-installation state of the computer. </param>
 public override void Rollback(IDictionary savedState)
 {
     base.Rollback(savedState);
     base.Context.LogMessage(Res.GetString("RestoringEventLog", this.Source));
     if (savedState["baseInstalledAndPlatformOK"] != null)
     {
         if (!(bool)savedState["logExists"])
         {
             EventLog.Delete(this.Log, ".");
         }
         else
         {
             object obj  = savedState["alreadyRegistered"];
             bool   flag = obj != null && (bool)obj;
             if (!flag && EventLog.SourceExists(this.Source, "."))
             {
                 EventLog.DeleteEventSource(this.Source, ".");
             }
         }
     }
 }
        /// <include file='doc\EventLogInstaller.uex' path='docs/doc[@for="EventLogInstaller.Rollback"]/*' />
        /// <devdoc>
        /// Called when this or another component in the installation has failed.
        /// </devdoc>
        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);

            Context.LogMessage(Res.GetString(Res.RestoringEventLog, Source));

            if (savedState["baseInstalledAndPlatformOK"] != null)
            {
                bool logExists = (bool)savedState["logExists"];
                if (!logExists)
                {
                    EventLog.Delete(Log, ".");
                }
                else
                {
                    bool   alreadyRegistered;
                    object alreadyRegisteredObj = savedState["alreadyRegistered"];
                    if (alreadyRegisteredObj == null)
                    {
                        alreadyRegistered = false;
                    }
                    else
                    {
                        alreadyRegistered = (bool)alreadyRegisteredObj;
                    }

                    if (!alreadyRegistered)
                    {
                        // delete the source we installed, assuming it succeeded. Then put back whatever used to be there.
                        if (EventLog.SourceExists(Source, "."))
                        {
                            EventLog.DeleteEventSource(Source, ".");
                        }
                    }
                }
            }
        }