ServiceInstaller クラスとは? わかりやすく解説

ServiceInstaller クラス

ServiceBase を拡張するクラスインストールしてサービス実装ます。このクラスは、サービス アプリケーションインストール時に、インストール ユーティリティ呼び出されます。

名前空間: System.ServiceProcess
アセンブリ: System.ServiceProcess (system.serviceprocess.dll 内)
構文構文

Public Class ServiceInstaller
    Inherits ComponentInstaller
Dim instance As ServiceInstaller
public class ServiceInstaller : ComponentInstaller
public ref class ServiceInstaller : public
 ComponentInstaller
public class ServiceInstaller extends ComponentInstaller
public class ServiceInstaller extends
 ComponentInstaller
解説解説

ServiceInstaller は、関連付けられているサービス固有の処理を行います。このクラスは、インストール ユーティリティが、サービス関連付けられているレジストリ値を HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services レジストリ キー内のサブキーに書き込む場合使用されます。サービスは、このサブキー内の ServiceName によって識別されます。サブキーには、サービス属す実行可能ファイルまたは DLL (ダイナミック リンク ライブラリ) の名前も含まれます。

サービスインストールするには、Installer クラスから継承するプロジェクト インストーラ クラス作成し、そのクラスの RunInstallerAttribute 属性true設定しますプロジェクト内では、サービス アプリケーションごとに 1 つの ServiceProcessInstaller インスタンス、およびアプリケーション内のサービスにつき 1 つServiceInstaller インスタンス作成しますプロジェクト インストーラ クラス コンストラクタ内で、ServiceProcessInstaller および ServiceInstaller インスタンス使用してサービスインストール プロパティ設定し、そのインスタンスを Installers コレクション追加します

メモメモ

  インストーラ インスタンス追加する場合にはコンストラクタ使用することをお勧めます。ただし、Install メソッド内の Installers コレクション追加する必要がある場合は、Uninstall メソッド内のコレクションにも同じよう追加する必要があります

Installer クラスから派生するクラス場合Installers コレクションの状態は、Install および Uninstall メソッド内と同じである必要があります。ただし、インストーラ インスタンスカスタム インストーラ クラス コンストラクタ内の Installers コレクション追加した場合は、Install メソッドおよび Uninstall メソッド間でコレクション保持する要はありません。インストール ユーティリティ呼び出しにより、RunInstallerAttribute 属性検索されます。属性true場合ユーティリティは、プロジェクト インストーラ関連付けられた Installers コレクション追加されすべてのサービスインストールます。RunInstallerAttributefalse場合、または存在しない場合インストール ユーティリティプロジェクト インストーラ無視します。

プロジェクト インストール クラス関連付けられた ServiceProcessInstaller は、プロジェクト内のすべての ServiceInstaller インスタンスに共通の情報インストールます。サービスインストール プロジェクト内の他のサービス区別される内容含まれている場合は、このメソッドによってサービス固有の情報インストールされます

メモメモ

ServiceName は、ServiceBase から派生したクラスの ServiceBase.ServiceName と必ず同じにする必要があります通常サービスServiceBase.ServiceName プロパティの値は、サービス アプリケーション実行可能ファイルMain() 関数内で設定されます。サービス コントロール マネージャは、ServiceInstaller.ServiceName プロパティ使用して、この実行可能ファイル内でサービス検索します

ServiceInstallerその他のプロパティは、プロジェクト インストーラInstallers コレクション追加する前または後に変更できます。たとえば、サービスの StartType で、サービス再起動時に自動的に起動するのか、ユーザー手動起動するようにするのかを設定できます

通常コード内の ServiceInstaller では、これらのメソッド呼び出しません。これらのメソッド呼び出すのは、一般にインストール ユーティリティだけです。インストール ユーティリティは、インストール プロセス中に、ServiceProcessInstaller.Install メソッドServiceInstaller.Install メソッド自動的に呼び出します。必要に応じてインストール済みすべてのコンポーネントRollback (または ServiceInstaller.Rollback) を呼び出すことによって、エラー回復します

インストール ユーティリティUninstall呼び出してオブジェクト削除します

アプリケーションのインストール ルーチンは、既にインストールされているコンポーネントに関する情報を、プロジェクト インストーラの Installer.Context を使用して自動的に維持します。この状態情報は、ServiceProcessInstaller インスタンスとして継続的に更新されます。ServiceInstaller インスタンスは、ユーティリティによってインストールされます通常コードでは状態情報明示的に変更する要はありません。

インストール実行されると、EventLogInstaller が自動的に作成されて、ServiceBase 派生クラス関連付けられているイベント ログ ソースインストールされます。このソースLog プロパティは、ServiceInstaller コンストラクタによって、コンピュータアプリケーション ログ設定されます。ServiceInstallerServiceName (サービスServiceBase.ServiceName同一にする必要があります) を設定すると、Source自動的に同じ値に設定されます。インストール失敗すると、ソースインストールは、前にインストールしたサービスの内容合わせてロールバックされます

サービス実行中場合Uninstall メソッド停止しようとします停止成功したかどうかかかわらずUninstallInstall行われた変更元に戻しますイベント ログに対して新しソース作成されると、このソース削除されます。

使用例使用例

Installer から継承されるMyProjectInstaller という名前のプロジェクト インストーラ作成する例を次に示します。この例では、2 つサービス "Hello-World Service 1" と "Hello-World Service 2" を格納するサービス実行可能ファイルがあることを前提にしています。インストール ユーティリティによって呼び出される MyProjectInstallerコンストラクタ内では、これらの各サービス対し ServiceInstaller オブジェクト作成され実行可能ファイルに対して ServiceProcessInstaller作成されます。インストール ユーティリティMyProjectInstaller有効なインストーラとして認識できるように、RunInstallerAttribute 属性true設定されます。

インストーラInstallers コレクション追加される前にオプションプロパティプロセス インストーラおよびサービス インストーラ設定されます。インストール ユーティリティMyProjectInstallerアクセスすると、InstallerCollection.Add の呼び出し通じて Installers コレクション追加されオブジェクト順番インストールされます。このプロセス中にインストーラは、インストールされているオブジェクトを示す状態情報保持しますこのためインストール失敗した場合でも、それぞれのオブジェクト順番回復できます

通常プロジェクト インストーラ クラスインスタンス明示的に作成されません。プロジェクト インストーラ クラス作成してRunInstallerAttribute 属性構文追加しますが、実際にクラス呼び出してインスタンス化するのはインストール ユーティリティ行います

Imports System
Imports System.Collections
Imports System.Configuration.Install
Imports System.ServiceProcess
Imports System.ComponentModel

<RunInstallerAttribute(True)> _
Public Class MyProjectInstaller
    Inherits Installer
    Private serviceInstaller1 As ServiceInstaller
    Private serviceInstaller2 As ServiceInstaller
    Private processInstaller As ServiceProcessInstaller
    
    
    Public Sub New()
        ' Instantiate installers for process and services.
        processInstaller = New ServiceProcessInstaller()
        serviceInstaller1 = New ServiceInstaller()
        serviceInstaller2 = New ServiceInstaller()
        
        ' The services will run under the system account.
        processInstaller.Account = ServiceAccount.LocalSystem
        
        ' The services will be started manually.
        serviceInstaller1.StartType = ServiceStartMode.Manual
        serviceInstaller2.StartType = ServiceStartMode.Manual
        
        ' ServiceName must equal those on ServiceBase derived classes.
            
        serviceInstaller1.ServiceName = "Hello-World Service 1"
        serviceInstaller2.ServiceName = "Hello-World Service 2"
        
        ' Add installers to collection. Order is not important.
        Installers.Add(serviceInstaller1)
        Installers.Add(serviceInstaller2)
        Installers.Add(processInstaller)
    End Sub
End Class

using System;
using System.Collections;
using System.Configuration.Install;
using System.ServiceProcess;
using System.ComponentModel;

[RunInstallerAttribute(true)]
public class MyProjectInstaller: Installer{
   private ServiceInstaller serviceInstaller1;
   private ServiceInstaller serviceInstaller2;
   private ServiceProcessInstaller processInstaller;

   public MyProjectInstaller(){
      // Instantiate installers for process and services.
      processInstaller = new ServiceProcessInstaller();
      serviceInstaller1 = new ServiceInstaller();
      serviceInstaller2 = new ServiceInstaller();

      // The services run under the system account.
      processInstaller.Account = ServiceAccount.LocalSystem;

      // The services are started manually.
      serviceInstaller1.StartType = ServiceStartMode.Manual;
      serviceInstaller2.StartType = ServiceStartMode.Manual;

      // ServiceName must equal those on ServiceBase derived classes.
            
      serviceInstaller1.ServiceName = "Hello-World Service 1";
      serviceInstaller2.ServiceName = "Hello-World Service 2";

      // Add installers to collection. Order is not important.
      Installers.Add(serviceInstaller1);
      Installers.Add(serviceInstaller2);
      Installers.Add(processInstaller);
   }
}

#using <System.dll>
#using <System.ServiceProcess.dll>
#using <System.Configuration.Install.dll>

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

[RunInstallerAttribute(true)]
public ref class MyProjectInstaller: public
 Installer
{
private:
   ServiceInstaller^ serviceInstaller1;
   ServiceInstaller^ serviceInstaller2;
   ServiceProcessInstaller^ processInstaller;

public:
   MyProjectInstaller()
   {
      
      // Instantiate installers for process and services.
      processInstaller = gcnew ServiceProcessInstaller;
      serviceInstaller1 = gcnew ServiceInstaller;
      serviceInstaller2 = gcnew ServiceInstaller;
      
      // The services run under the system account.
      processInstaller->Account = ServiceAccount::LocalSystem;
      
      // The services are started manually.
      serviceInstaller1->StartType = ServiceStartMode::Manual;
      serviceInstaller2->StartType = ServiceStartMode::Manual;
      
      // ServiceName must equal those on ServiceBase derived classes.
            
      serviceInstaller1->ServiceName = "Hello-World Service 1";
      serviceInstaller2->ServiceName = "Hello-World Service 2";
      
      // Add installers to collection. Order is not important.
      Installers->Add( serviceInstaller1 );
      Installers->Add( serviceInstaller2 );
      Installers->Add( processInstaller );
   }

};

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

/** @attribute RunInstallerAttribute(true)
 */
public class MyProjectInstaller extends Installer
{
    private ServiceInstaller serviceInstaller1;
    private ServiceInstaller serviceInstaller2;
    private ServiceProcessInstaller processInstaller;

    public MyProjectInstaller()
    {
        // Instantiate installers for process and services.
        processInstaller = new ServiceProcessInstaller();
        serviceInstaller1 = new ServiceInstaller();
        serviceInstaller2 = new ServiceInstaller();

        // The services run under the system account.
        processInstaller.set_Account(ServiceAccount.LocalSystem);

        // The services are started manually.
        serviceInstaller1.set_StartType(ServiceStartMode.Manual);
        serviceInstaller2.set_StartType(ServiceStartMode.Manual);

        // ServiceName must equal those on ServiceBase derived classes.
            
        serviceInstaller1.set_ServiceName("Hello-World Service 1");
        serviceInstaller2.set_ServiceName("Hello-World Service 2");

        // Add installers to collection. Order is not important.
        get_Installers().Add(serviceInstaller1);
        get_Installers().Add(serviceInstaller2);
        get_Installers().Add(processInstaller);
    } //MyProjectInstaller
} //MyProjectInstaller
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Configuration.Install.Installer
         System.Configuration.Install.ComponentInstaller
          System.ServiceProcess.ServiceInstaller
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ServiceInstaller メンバ
System.ServiceProcess 名前空間
ServiceBase.ServiceName プロパティ
ServiceProcessInstaller
ServiceBase クラス
ServiceBase.EventLog プロパティ



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ServiceInstaller クラス」の関連用語

ServiceInstaller クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ServiceInstaller クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS