UninstallAction Enumeration

Specifies what an installer should do during an uninstallation.

Namespace: System.Configuration.Install
Assembly: System.Configuration.Install (in system.configuration.install.dll)

'Declaration
Public Enumeration UninstallAction
'Usage
Dim instance As UninstallAction

public enum UninstallAction
public enum UninstallAction

 Member nameDescription
NoActionLeaves the resource created by the installer as is. 
RemoveRemoves the resource the installer created. 

The following sample creates a custom uninstaller that inherits the Installer class. In the overridden Uninstall function, the UninstallAction enumeration is set based on user input. If the input is "n", the custom uninstaller will not take any action on the resource in the event log entered by the user. Otherwise, it will remove the resource from the event log.

Imports System
Imports System.Diagnostics
Imports System.Collections
Imports System.ComponentModel
Imports System.Configuration.Install

<RunInstaller(True)>  _
Public Class MyUninstallActionClass
   Inherits Installer
   Private myInstaller As New EventLogInstaller()

   ' Override the 'Install' method.
   Public Overrides Sub Install(savedState As IDictionary)
      Console.Write("Enter a new log to create (eg: MyLog ): ")
      myInstaller.Log = Console.ReadLine()
      Console.Write("Enter a source for log (eg: MySource ): ")
      myInstaller.Source = Console.ReadLine()
      Installers.Add(myInstaller)
      MyBase.Install(savedState)
   End Sub 'Install

   ' Override the 'Commit' method.
   Public Overrides Sub Commit(savedState As IDictionary)
      MyBase.Commit(savedState)
   End Sub 'Commit

   ' Override the 'Rollback' method.
   Public Overrides Sub Rollback(savedState As IDictionary)
      MyBase.Rollback(savedState)
   End Sub 'Rollback

   Public Overrides Sub Uninstall(savedState As IDictionary)

      Console.Write("Enter a source from log to uninstall(eg: MySource ): ")
      myInstaller.Source = Console.ReadLine()

      Console.Write("Do you want to uninstall, press 'y' for 'YES' and 'n' for 'NO':")
      Dim myUninstall As String = Console.ReadLine()

      If myUninstall = "n" Then
         ' No action to be taken on the resource in the event log.
         myInstaller.UninstallAction = System.Configuration.Install.UninstallAction.NoAction
      Else
         ' Remove the resource from the event log.
         myInstaller.UninstallAction = System.Configuration.Install.UninstallAction.Remove
      End If
      Installers.Add(myInstaller)
      MyBase.Uninstall(savedState)
   End Sub 'Uninstall

   Public Shared Sub Main()
      Console.WriteLine("Syntax for install: installutil.exe "+ _
                        "UninstallAction_NoAction_Remove_3.exe ")
      Console.WriteLine("Syntax for uninstall: installutil.exe /u " + _
                        "UninstallAction_NoAction_Remove_3.exe ")
   End Sub 'Main

End Class 'MyUninstallActionClass

import System.*;
import System.Diagnostics.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.Configuration.Install.*;

/** @attribute RunInstaller(true)
 */
public class MyUninstallActionClass extends Installer
{
    private EventLogInstaller myInstaller = new EventLogInstaller();

    // Override the 'Install' method.
    public void Install(IDictionary savedState)
    {
        Console.Write("Enter a new log to create (eg: MyLog ): ");
        myInstaller.set_Log(Console.ReadLine());
        Console.Write("Enter a source for log (eg: MySource ): ");
        myInstaller.set_Source(Console.ReadLine());
        get_Installers().Add(myInstaller);
        super.Install(savedState);
     //Install

    // Override the 'Commit' method.
    public void Commit(IDictionary savedState)
    {
        super.Commit(savedState);
     //Commit

    // Override the 'Rollback' method.
    public void Rollback(IDictionary savedState)
    {
        super.Rollback(savedState);
     //Rollback

    public void Uninstall(IDictionary savedState)
    {
        Console.Write("Enter a source from log to uninstall(eg: MySource ): ");
        myInstaller.set_Source(Console.ReadLine());

        Console.Write("Do you want to uninstall, press 'y' for 'YES' and 'n'" 
            + " for 'NO':");
        String myUninstall = Console.ReadLine();

        if (myUninstall.Equals("n")) {
            // No action to be taken on the resource in the event log.
            myInstaller.set_UninstallAction(System.Configuration.Install.
                UninstallAction.NoAction);
        
        else {
            // Remove the resource from the event log.
            myInstaller.set_UninstallAction(System.Configuration.Install.
                UninstallAction.Remove);
        
        get_Installers().Add(myInstaller);
        super.Uninstall(savedState);
     //Uninstall

    public static void main(String[] args)
    {
        Console.WriteLine("Syntax for install: installutil.exe " 
            + "UninstallAction_NoAction_Remove_3.exe ");
        Console.WriteLine("Syntax for uninstall: installutil.exe /u " 
            + "UninstallAction_NoAction_Remove_3.exe ");
     //main
 //MyUninstallActionClass

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: