次の方法で共有


UninstallAction 列挙体

アンインストール中のインストーラの動作を指定します。

<Serializable>
Public Enum UninstallAction
[C#]
[Serializable]
public enum UninstallAction
[C++]
[Serializable]
__value public enum UninstallAction
[JScript]
public
   Serializable
enum UninstallAction

メンバ

メンバ名 説明
NoAction インストーラによって作成されたリソースをそのまま残します。
Remove インストーラによって作成されたリソースを削除します。

使用例

[Visual Basic, C#, C++] Installer クラスを継承するカスタム アンインストーラを作成する例を次に示します。この例では Uninstall 関数のオーバーライドで、ユーザー入力を基に UninstallAction 列挙体を設定します。ユーザー入力が "n" の場合、ユーザーが入力したイベント ログのリソースに対してカスタム アンインストーラは一切の処理を行いません。"n" 以外の場合は、イベント ログからリソースを削除します。

 
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

[C#] 
using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

[RunInstaller(true)]
public class MyUninstallActionClass : Installer 
{
   EventLogInstaller myInstaller = new EventLogInstaller();
   
   // Override the 'Install' method.
   public override void Install(IDictionary savedState)
   {
      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 );
      base.Install(savedState);
   }

   // Override the 'Commit' method.
   public override void Commit(IDictionary savedState)
   {
      base.Commit(savedState);
   }

   // Override the 'Rollback' method.
   public override void Rollback(IDictionary savedState)
   {
      base.Rollback(savedState);
   }
   public override void Uninstall(IDictionary savedState)
   {
      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':");
      string myUninstall = Console.ReadLine();
     
      if( myUninstall == "n" )
      {
         // 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;
      }
      Installers.Add( myInstaller );
      base.Uninstall(savedState);
   }
   public static void 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 ");
   }

}

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::Configuration::Install;

[RunInstaller(true)]
__gc class MyUninstallActionClass : public Installer {
private:
    EventLogInstaller* myInstaller;

public:
    MyUninstallActionClass() {
        myInstaller = new EventLogInstaller();
    }

    // Override the 'Install' method.
    void Install(IDictionary* savedState) {
        Console::Write(S"Enter a new log to create (eg: MyLog): ");
        myInstaller->Log = Console::ReadLine();
        Console::Write(S"Enter a source for log (eg: MySource): ");
        myInstaller->Source = Console::ReadLine();
        Installers->Add(myInstaller);
        Installer::Install(savedState);
    }

    // Override the 'Commit' method.
    void Commit(IDictionary* savedState) {
        Installer::Commit(savedState);
    }

    // Override the 'Rollback' method.
    void Rollback(IDictionary* savedState) {
        Installer::Rollback(savedState);
    }

    void Uninstall(IDictionary* savedState) {
        Console::Write(S"Enter a source from log to uninstall(eg: MySource): ");
        myInstaller->Source = Console::ReadLine();

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

        if (myUninstall->Equals(S"n")) {
            // No action to be taken on the resource in the event log.
            myInstaller->UninstallAction = UninstallAction::NoAction;
        } else {
            // Remove the resource from the event log.
            myInstaller->UninstallAction = UninstallAction::Remove;
        }
        Installers->Add(myInstaller);
        Installer::Uninstall(savedState);
    }
};

int main() {
    Console::WriteLine(S"Syntax for install: installutil.exe UninstallAction_NoAction_Remove_3.exe ");
    Console::WriteLine(S"Syntax for uninstall: installutil.exe /u UninstallAction_NoAction_Remove_3.exe ");
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Configuration.Install

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Configuration.Install (System.Configuration.Install.dll 内)

参照

System.Configuration.Install 名前空間 | Installer | Uninstall